Sending key down behaves like key press (down then up)

Ask gaming related questions (AHK v1.1 and older)
javic
Posts: 2
Joined: 20 May 2024, 18:04

Sending key down behaves like key press (down then up)

Post by javic » 20 May 2024, 18:51

I play a lot of video games and use AHK extensively for customizing in-game controls. For decades now I've been using definitions like this:

MButton::Send {x down}

where "x" is the key I use for forward movement in some game. In the game, I press MButton and I get a key-down event with no key-up, causing the game to "think" I'm holding the key, so my character moves forward automatically. To stop, I tap "x" which generates a key-up event ending forward movement. Works great, or rather it has worked great until now.

Today, this definition stopped working. Pressing MButton generates key-down followed immediately (as far as I can tell) by key-up. So if I press Mbutton I get one and only one "x".

I've tested this definition in the past by running the script, opening some text editor (vim in my case) and pressing MButton. Until today, that action would generate an endless series of "x" characters just as happens when I actually press and hold the "x" key (like a game, the editor "thinks" I'm holding the key down). Today, the same test generates a single "x", strongly suggesting key-down is followed immediately by key-up.

I've tried multiple AHK scripts, multiple trigger keys (mouse buttons, various keys), and multiple values for "x". They all behave the same: a single key-down key-up event. I've also tried AHK V1 and V2; both versions exhibit the same behavior (historically I've been using V1). And I've tried the usual quick fixes of removing and reinstalling AHK, and rebooting my machine.

FWIW All other key and mouse definitions work fine.

I'm baffled as to what could possibly be causing this situation, and would appreciate very much any ideas anybody has for how to diagnose (and eventually fix) the issue.

Rohwedder
Posts: 7735
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Sending key down behaves like key press (down then up)

Post by Rohwedder » 21 May 2024, 00:51

Hallo,
Until today, that action would generate an endless series of "x" characters just as happens when I actually press and hold the "x" key (like a game, the editor "thinks" I'm holding the key down).
This behavior is called auto-repeat a driver/hardware feature https://www.autohotkey.com/docs/v2/lib/Send.htm#Repeating_or_Holding_Down_a_Key.
It should not occur when the mouse buttons are pressed. Your keyboard driver apparently had a bug that has now been fixed in an update.
Try:

Code: Select all

MButton::Repeat("x", 30) ; a Timer sends {Blind}{x Down} every 30 ms
MButton Up::Repeat("x") ; deletes the Timer and send {Blind}{x Up}

Repeat(Key, Period:=0) {
    Static Repeat := {}
    Repeat[Key] ?: Repeat[Key] := Func("KeyDown").Bind(Key)
    Timer := Repeat[Key]
    SetTimer,% Timer,% Period ? Period : "Delete"
    SendInput,% Period?"":"{Blind}{" Key " Up}" Repeat[Key]:=""
} KeyDown(Key) {
    SendInput, {Blind}{%Key% Down}
}

javic
Posts: 2
Joined: 20 May 2024, 18:04

Re: Sending key down behaves like key press (down then up)

Post by javic » 21 May 2024, 08:13

Never mind. I tried again this morning and it's working now. :oops: Not sure what was going on yesterday when I posted, but I suspect some kind of user error.

Post Reply

Return to “Gaming Help (v1)”