360 controller strange behaviour? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Crimson_V
Posts: 9
Joined: 14 May 2016, 06:54

360 controller strange behaviour?

30 Apr 2017, 14:52

so i have made stuff more complicated than this, but for some reason i can't figure out what i'm doing wrong

My script is very simple:

Code: Select all

Joy7 & Joy8::
Process,Close,myapp.exe
ExitAPP
I have 2 360 controllers at hand and with one my script fires with only the joy8 pressed, and the other one does absolutely nothing both controller seem to be operating fine in all other cases, and my script obviously works with keyboard keys, so what's going on here?

edit: the first controller works fine with single keys, but the second one won't trigger anything ahk related,
but ahk Joystick Test Script seems to be returning correct results when keys are pressed so as far as i can tell GetKeyState loop does get the correct key, so why is this happening? i'm definitely doing something wrong. :headwall:
Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: 360 controller strange behaviour?

30 Apr 2017, 16:15

Check this section on Hotkeys
https://autohotkey.com/docs/Hotkeys.htm#combo
It states you can't combo with them.
Crimson_V
Posts: 9
Joined: 14 May 2016, 06:54

Re: 360 controller strange behaviour?

30 Apr 2017, 16:39

Well i guess that's how it is thanks for letting me know. (changed my script to a GetKeyState loop as a workaround)
nismo
Posts: 19
Joined: 22 Dec 2016, 13:57

Re: 360 controller strange behaviour?  Topic is solved

30 Apr 2017, 19:22

Nightwolf85 wrote:Check this section on Hotkeys
https://autohotkey.com/docs/Hotkeys.htm#combo
It states you can't combo with them.

Yes you can combo but it's a bit tricky, I do it this way:

Code: Select all

#persistent

; Example of doing select+start button combo on X360 gamepad.

JoystickNumber = 1                    ; What gamepad to use
ButtonSelect = 7                        ; what is the button of gamepad to use
ButtonStart = 8                          ; the another button to use

KeyButtonSelect = 7                  ; the key send by the button
KeyButtonStart = 8                    ; the key send by the button
KeyButtonSelectStart = !{F4}      ; the key or keys to send when both buttons pressed at same time

JoystickPrefix = %JoystickNumber%Joy
Hotkey, %JoystickPrefix%%ButtonSelect%, ButtonSelect
Hotkey, %JoystickPrefix%%ButtonStart%, ButtonStart

ButtonStart:
GetKeyState(JoystickPrefix . ButtonStart)  ; state of button 1
If GetKeyState(JoystickPrefix . ButtonSelect) ; state of button 2
{
send %KeyButtonSelectStart%             ; send combo
return
}
else                             
Send {%KeyButtonStart% down}            ; if not send key defined for the button
SetTimer, WaitForButtonStartUp, 10
return

; now we do the reverse
; just because if we press button 2 before than button 1.

ButtonSelect:
GetKeyState(JoystickPrefix . ButtonSelect)
If GetKeyState(JoystickPrefix . ButtonStart)
{
send %KeyButtonSelectStart%
{
ExitApp
}
return
}
else
Send {%KeyButtonSelect% down} 
SetTimer, WaitForButtonSelectUp, 10
return

WaitForButtonStartUp:
if GetKeyState(JoystickPrefix . ButtonStart)
    return  ; button still hold.
; else button released.
SetTimer, WaitForButtonStartUp, off
Send {%KeyButtonStart% up}  ; release the button.
return

WaitForButtonSelectUp:
if GetKeyState(JoystickPrefix . ButtonSelect)
    return  ;button still hold.
; else button released.
SetTimer, WaitForButtonSelectUp, off
Send {%KeyButtonSelect% up}  ; release the button.
return
I hope this help, regards.
Crimson_V
Posts: 9
Joined: 14 May 2016, 06:54

Re: 360 controller strange behaviour?

01 May 2017, 03:17

nismo wrote:
Nightwolf85 wrote:Check this section on Hotkeys
https://autohotkey.com/docs/Hotkeys.htm#combo
It states you can't combo with them.

Yes you can combo but it's a bit tricky, I do it this way:

Code: Select all

#persistent

; Example of doing select+start button combo on X360 gamepad.

JoystickNumber = 1                    ; What gamepad to use
ButtonSelect = 7                        ; what is the button of gamepad to use
ButtonStart = 8                          ; the another button to use

KeyButtonSelect = 7                  ; the key send by the button
KeyButtonStart = 8                    ; the key send by the button
KeyButtonSelectStart = !{F4}      ; the key or keys to send when both buttons pressed at same time

JoystickPrefix = %JoystickNumber%Joy
Hotkey, %JoystickPrefix%%ButtonSelect%, ButtonSelect
Hotkey, %JoystickPrefix%%ButtonStart%, ButtonStart

ButtonStart:
GetKeyState(JoystickPrefix . ButtonStart)  ; state of button 1
If GetKeyState(JoystickPrefix . ButtonSelect) ; state of button 2
{
send %KeyButtonSelectStart%             ; send combo
return
}
else                             
Send {%KeyButtonStart% down}            ; if not send key defined for the button
SetTimer, WaitForButtonStartUp, 10
return

; now we do the reverse
; just because if we press button 2 before than button 1.

ButtonSelect:
GetKeyState(JoystickPrefix . ButtonSelect)
If GetKeyState(JoystickPrefix . ButtonStart)
{
send %KeyButtonSelectStart%
{
ExitApp
}
return
}
else
Send {%KeyButtonSelect% down} 
SetTimer, WaitForButtonSelectUp, 10
return

WaitForButtonStartUp:
if GetKeyState(JoystickPrefix . ButtonStart)
    return  ; button still hold.
; else button released.
SetTimer, WaitForButtonStartUp, off
Send {%KeyButtonStart% up}  ; release the button.
return

WaitForButtonSelectUp:
if GetKeyState(JoystickPrefix . ButtonSelect)
    return  ;button still hold.
; else button released.
SetTimer, WaitForButtonSelectUp, off
Send {%KeyButtonSelect% up}  ; release the button.
return
I hope this help, regards.
Thank you your script is much more elegant then mine and doesn't require a loop :dance:
nismo
Posts: 19
Joined: 22 Dec 2016, 13:57

Re: 360 controller strange behaviour?

01 May 2017, 05:21

Nice! I'm glad to help, then maybe you can check my post as topic solved.

Regards.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Aqualest and 105 guests