UPDATED-STATEMENT: 20181102@112800@SUN Post created UPDATED-STATEMENT: 20181104@133200@TUE Suggested pre-requisite code that worked only for a short while UPDATED-STATEMENT: 20190101@184318@TUE Pre-requisite code no longer works in csgo anymore and never had with kf2 so I need help with another solution as to why it doesn't work perhaps an update happened preventing it from working for csgo


How to hold w when holding XButton1 on Logitech G502 using AutoHotKey? Problem is when holding the key with the script below it just sends a single output and not producing typical Windows-behavior which is really holding it (see below for example). Keep in mind that just because i'm intentionally using this for the purpose of playing fps games, but globally remapping it is much easier than including every game I so happen to play to be part of changing the LogitechG502's control buttons.

I think it's cool to move forward in-game while grabbing hot cheetos with my other hand

Would suggestions here make games wanna change?

Are games becoming dependent to knowing what their users are keystroking?


  • I don't have a way to remap XButton1 on my LogitechG502 to replicate holding w
    • ahk-while command works but doesn't behave properly and acts as a press-release-press-release really fast even when slowed down using ahk-sleep
    • see below for solution on setting up several ahk-commands to remap LogitechG502's XButton1 to w to move forward while ingame


  • None-so-far
    • Code suggested by user3419297 no longer works after a csgo update that was relevant to this very post


  • Notworking: XButton1::SendInput, w ; mouse advanced button back as holding forward in-game
    • Holding for 3-sec, XButton1 (w/ script above) gives me: w
    • Holding for 3-sec, w gives me: wwwwwwwwwwwwwwwwwwwwwwwwww
  • Worksbutimproperuseoftoggle (or fast repetition of pressing down W):
    • doesn't replicate holding w properly as this method is way faster of a repeat even when slowed down by ahk-sleep
       while GetKeyState("XButton1", "P")
       Send w
  • Workbutnotanymore
    • This pre-requisite code doesn't work anymore after 2-months of usage and perhaps that may be due to a csgo update as I don't have another fps shooter to test it with
#SingleInstance Force
#If WinActive ahk_exe csgo.exe || WinActive ahk_exe game2.exe || WinActive ahk_exe  game3.exe
  • Unclear what are your problem and solution.
    – harrymc
    Nov 2, 2018 at 13:27
  • Problem is that the suggested answer by @user3419297, gets the job done by actually holding w, but it's too fast and not properly replicating how window's holds down a key.
    – fohrums
    Nov 3, 2018 at 12:28

2 Answers 2


This should work:

; maximum number of hotkeys that can be pressed within 2 seconds (default rate of hotkey activations)
; without triggering a warning dialog:
#MaxHotkeysPerInterval 10000

while GetKeyState("XButton1", "P")
    Send w
    Sleep 20 ; ms or more if you  want to reduce the frequency of the send command 




  • Tested working, but it is really fast and replacing Send to SendInput is even faster. It isn't the same behavior as holding w. I am also not understanding the reason for the pound-sign line with the interval 10000.
    – fohrums
    Nov 3, 2018 at 11:58
  • You can reduce the frequency of the send command within the loop by adding a sleep (time before repeating the send command) in it. See the edited answer. Nov 3, 2018 at 13:04
  • That does help with it being fast, but when testing it in-game I get movefoward-stop-moveforward-stop action. It's not the right type of behavior i'm looking for. Maybe it isn't with the ahk-while, but perhaps a way to just hold down a key?
    – fohrums
    Nov 4, 2018 at 13:04

Try also the remapping:

#SingleInstance Force

#IfWinActive Title of my game



Replace Title of my game with the exact title of the game window as shown in Window Spy.



You can use the #If- or the #IfWinActive- directive to create context-sensitive hotkeys for more than one applications/windows:

#If WinActive("Title of my game1") || WinActive("Title of my game2") ; "||" means "OR"


#If WinActive("Title of my game3")  


#If  ; turn off context sensitivity

; In all other applications/windows you can make XButton1 and XButton2 to do something else, e.g.:

XButton1:: Send ^c  ; copy
XButton2:: Send ^v  ; paste


  • This works, but I wanted to avoid having to implement the title of game and create multiple same code for each (gametitle). So the lines w/ the poundsign is needed including the last line #ifwinactive?
    – fohrums
    Nov 6, 2018 at 12:35
  • 1
    See EDIT in my answer. Nov 6, 2018 at 13:06
  • That helps with the redundancy, but this code doesn't work with Killing Floor 2. Do you know if it's because it uses the Unreal Engine?
    – fohrums
    Dec 7, 2018 at 23:33
  • This is strange, but this all of a sudden doesn't work for csgo anymore. Not sure if it was an update or what.
    – fohrums
    Jan 1, 2019 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.