Gamepad button longpress

Ask gaming related questions (AHK v1.1 and older)
artemgm
Posts: 3
Joined: 28 Nov 2021, 06:09

Gamepad button longpress

Post by artemgm » 28 Nov 2021, 06:20

Hey! I'm trying to create a script, where I press the guide button (vk07) on my xinput gamepad. If I long press it - it performs alt + f4, short press opens an exe file.
That's how it looks like rn:

Code: Select all

$vk07::                                        		; Long press (> 0.5 sec) on * substitutes the dot multiply
    KeyWait, vk07, T0.5                              ; Wait no more than 0.5 sec for key release (also suppress auto-repeat)
    If ErrorLevel {                                    	; timeout, so long press
        Send !{f4}                               
        KeyWait, vk07
    } Else                                              ; otherwise...
        Run "C:\Users\Artem\AppData\Local\Playnite\Playnite.FullscreenApp.exe"                               
Return
[Mod edit: [code][/code] tags added.]

However, it only opens the exe right away, no matter if I shortpress or longpress. But, if I replace the vk07 with letter z, for example, it works as it should and the long press doesn't trigger the opening of an exe.
How can I make it work for the gamepad?
Last edited by BoBo on 28 Nov 2021, 11:47, edited 1 time in total.

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Gamepad button longpress

Post by mikeyww » 28 Nov 2021, 09:53

I wonder what happens with a scan code.

Code: Select all

SC02C:: ; z
KeyWait, %A_ThisHotkey%, T.5
SendInput % ErrorLevel ? "Held`n" : "Not held`n"
KeyWait, %A_ThisHotkey%
Return

artemgm
Posts: 3
Joined: 28 Nov 2021, 06:09

Re: Gamepad button longpress

Post by artemgm » 28 Nov 2021, 11:07

@mikeyww guide button doesn't trigger SC02C

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Gamepad button longpress

Post by mikeyww » 28 Nov 2021, 13:20

That is a demonstration. You could look for the scan code in your case.

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

Re: Gamepad button longpress

Post by Rohwedder » 28 Nov 2021, 14:11

Hallo,
untested, I have no guide button:

Code: Select all

$vk07:: ; Long press (> 0.5 sec) on * substitutes the dot multiply
While, GetKeyState("vk07") And !ErrorLevel := A_TimeSinceThisHotkey > 500
	Sleep, 50 ; Wait no more than 0.5 sec for key release (also suppress auto-repeat)
If ErrorLevel
{ ; timeout, so long press
	Send !{f4}
	While, GetKeyState("vk07")
		Sleep, 50
}
Else ; otherwise...
	Run "C:\Users\Artem\AppData\Local\Playnite\Playnite.FullscreenApp.exe"
Return

artemgm
Posts: 3
Joined: 28 Nov 2021, 06:09

Re: Gamepad button longpress

Post by artemgm » 29 Nov 2021, 17:22

@Rohwedder
thank you so much you're my Romeo from Germany! It works flawlessly... I just tested and comment that and like I'm drunk I haven't read the code even to see what has changed loll. you could've just implement some virus into it and I'd steal eat it. sending love

Post Reply

Return to “Gaming Help (v1)”