win10_v1803.17134.345_home
autohotkeyahk_v1.1.30.00

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

PROBLEM

  • 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

SOLUTION

  • This pre-requisite code behaves properly, but needs to be defined as per gametitle (only if there was a way to globally re-map it). Not only that, but doesn't work for all games like Killing Floor 2 as Counter-strike Global Offensive csgo works so far.
#NoEnv
#SingleInstance Force
#InstallKeybdHook
#InstallMouseHook
#UseHook
#IfWinActive Title of my game
    XButton1::w
#IfWinActive

SAMPLE

  • 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
  • worksbuttoofast:
$XButton1::
       while GetKeyState("XButton1", "P")
       Send w
       return
  • doesn't replicate holding w properly as this method is way faster of a repeat even when slowed down by ahk-sleep
  • Unclear what are your problem and solution. – harrymc Nov 2 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 at 12:28

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

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

Untested.

https://autohotkey.com/docs/commands/While.htm

https://autohotkey.com/docs/commands/_MaxHotkeysPerInterval.htm

  • 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 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. – user3419297 Nov 3 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 at 13:04

Try also the remapping:

#NoEnv
#SingleInstance Force
#InstallKeybdHook
#InstallMouseHook
#UseHook

#IfWinActive Title of my game

    XButton1::w

#IfWinActive

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

https://autohotkey.com/docs/commands/_IfWinActive.htm

EDIT:

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"

    XButton1::w
    XButton2::x

#If WinActive("Title of my game3")  

    XButton1::a
    XButton2::b

#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

https://autohotkey.com/docs/commands/_If.htm

  • 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 at 12:35
  • 1
    See EDIT in my answer. – user3419297 Nov 6 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 at 23:33

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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