Binding action to two combined joystick buttons Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Redbird
Posts: 13
Joined: 03 Jun 2019, 17:25

Binding action to two combined joystick buttons

Post by Redbird » 12 Jun 2021, 17:43

Hi. I'm trying to get AHK to send the 'a' keystroke when I press Select (Joy7) and Start (Joy8) simultaneously on my 360 gamepad:

Code: Select all

Joy7 & Joy8::	Send, a
Unfortunately, for some reason this just causes Start to send 'a'. Select does nothing. Am I doing something wrong?

User avatar
boiler
Posts: 16774
Joined: 21 Dec 2014, 02:44

Re: Binding action to two combined joystick buttons  Topic is solved

Post by boiler » 12 Jun 2021, 22:20

Redbird wrote: Am I doing something wrong?
Yes, you’re trying to do something the documentation specifically says cannot be done:
Hotkey Custom Combinations wrote:You can define a custom combination of two keys (except joystick buttons) by using " & " between them.
Try creating a hotkey out of one of the buttons and check the state of the other using GetKeyState() to see if they’re pressed simultaneously.

Redbird
Posts: 13
Joined: 03 Jun 2019, 17:25

Re: Binding action to two combined joystick buttons

Post by Redbird » 13 Jun 2021, 00:56

I didn't realize that wasn't supported. Why not?

Anyway, thank you for your help. Your suggestion worked:

Code: Select all

Joy7::
GetKeyState, StateJoy8, Joy8
if (StateJoy8 = "D")
	Send, a
Return

Joy8::
GetKeyState, StateJoy7, Joy7
if (StateJoy7 = "D")
	Send, a
Return

User avatar
boiler
Posts: 16774
Joined: 21 Dec 2014, 02:44

Re: Binding action to two combined joystick buttons

Post by boiler » 13 Jun 2021, 06:19

Redbird wrote: I didn't realize that wasn't supported. Why not?
I imagine it has to do with Windows’ ability to set up keyboard and mouse hooks in a way that it isn’t available for joystick buttons.

Redbird wrote: Anyway, thank you for your help. Your suggestion worked
You’re welcome. By the way, since the GetKeyState command is deprecated, I suggest using the GetKeyState() function instead. It also eliminates the need for a temporary variable:

Code: Select all

Joy7::
if GetKeyState("Joy8")
	Send, a
Return

Joy8::
if GetKeyState("Joy7")
	Send, a
Return

Redbird
Posts: 13
Joined: 03 Jun 2019, 17:25

Re: Binding action to two combined joystick buttons

Post by Redbird » 13 Jun 2021, 15:24

Thank you, that makes the code even simpler.

Post Reply

Return to “Ask for Help (v1)”