-1

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

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

Would suggestions here make games wanna change?

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

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

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

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
  • 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
$XButton1::
       while GetKeyState("XButton1", "P")
       Send w
       return
  • 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
#NoEnv
#SingleInstance Force
#InstallKeybdHook
#InstallMouseHook
#UseHook
#If WinActive ahk_exe csgo.exe || WinActive ahk_exe game2.exe || WinActive ahk_exe  game3.exe
    XButton1::w
#IfWinActive
2
  • 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

3 Answers 3

1

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

3
  • 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.
    – Relax
    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
1

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

4
  • 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.
    – Relax
    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
0
XButton1::
;ToolTip, XButton1 down
SendInput {w down}
Return

XButton1 Up::
SendInput {w up}
;ToolTip, XButton1 up
Return

-The line "XButton1::" specifies a hotkey for XButton1 which is one of the side buttons on the mouse. This means that the following lines, until Return, will be run when XButton1 is pressed. -The line "SendInput {w down}" causes a "w down" event to be sent, fulfilling the request of the OP to press a key (send a w down event first), without sending the corresponding keyup event if you just hit "SendInput w". With "down", the key is held until an "up" is sent. -The Line "Return" ends the hotkey for XButton1.

-The line "XButton1 Up::" specifies a hotkey which triggers when Xbutton is released (goes up). -The line "SendInput {w up}" sends the key up event for the key w. Since this is attached to the "XButton1 up" hotkey, this means that the hotkey fulfills the OP's request of using a mouse button to hold another key. -The line "Return" ends the "XButton1 up" hotkey. +the ";ToolTip" lines are comments that I could remove but it is informative to uncomment them and see that the ToolTips are fired upon pressing and releasing Xbutton1.

You can change the "XButton1" and "w" tokens to different keys to achieve the effect you need.

2
  • 1
    You need to add at least a few sentences of explanation to this in order to make it an answer. Jun 18, 2023 at 4:23
  • Please edit your answer and provide and explanation of the code Jun 18, 2023 at 4:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .