Rebinding "Hotkey" Variable problems. Topic is solved

Ask gaming related questions (AHK v1.1 and older)
User avatar
RealThingerthing
Posts: 13
Joined: 07 Sep 2022, 01:01

Rebinding "Hotkey" Variable problems.

Post by RealThingerthing » 24 Mar 2023, 18:20

Hi, i'm trying to do a thing where if your controller is not doing the right joystick inputs you can rebind the hotkey for the correct joystick input, its probably terribly worded but whatever. (for me my controller sends in joy1 on one adapter and joy3 on another when pressing the same button).

Code: Select all

lastbutton := 

Keys := "Joy1,Joy2,Joy3,Joy4,Joy5,Joy6,Joy7,Joy8,Joy9,Joy10,Joy11,Joy12,Joy13,Joy14,Joy15"

GetKeyPress(keyStr) {
	keys := StrSplit(keyStr, ",")
	loop
		for each, key in keys
			if GetKeyState(key)
				return key
}

; - gui part

Gui lastbutton: new, -resize
Gui Font, s9, Consolas
Gui Show, w200 h130
Gui Add, Button, grebind x50 y0 w100 h25, REBIIIIIIIND!
Gui Add, Text, x50 y10 w50, w50, %lastbutton%
Return

Hotkey, %lastbutton%, lastbuttonlabel, ON

rebind:
    Input := GetKeyPress(Keys)
    lastbutton := %Input%
    MsgBox, You pressed %Input%
return

lastbuttonlabel:
	send, a
	Return
Everything in here works when i'm not trying to use joystick inputs but with keyboard inputs only which is a start but not helpful. What am I missing? I'm not exactly sure where it could be but maybe somehow its not setting the variable correctly or maybe hotkey just doesn't work with joystick inputs.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Rebinding "Hotkey" Variable problems.  Topic is solved

Post by swagfag » 24 Mar 2023, 19:14

ur Hotkey command isnt doing anything

Code: Select all

......
Gui Add, Text, x50 y10 w50, w50, %lastbutton%
Return ; <<<<<<<<<<<<< end of auto-execute section

Hotkey, %lastbutton%, lastbuttonlabel, ON ; <<<<<<<<<<<< this is unreachable code

rebind:
    Input := GetKeyPress(Keys)
.....

User avatar
RealThingerthing
Posts: 13
Joined: 07 Sep 2022, 01:01

Re: Rebinding "Hotkey" Variable problems.

Post by RealThingerthing » 24 Mar 2023, 21:46

I finally got it all working except for one teensy tiny problem.

Code: Select all

vgreen := "Joy1"
vred := "Joy2"
vyellow := "Joy3"
vblue := "Joy4"
vorange := "Joy5"

keys := "Joy1,Joy2,Joy3,Joy4,Joy5,Joy6,Joy7,Joy8,Joy9,Joy10,Joy11,Joy12,Joy13,Joy14,Joy15"

GetKeyPress(keyStr) {
	keys := StrSplit(keyStr, ",")
	loop
		for each, key in keys
			if GetKeyState(key)
				return key
}

Hotkey, %vgreen%, green, On
Hotkey, %vred%, red, On
Hotkey, %vyellow%, yellow, On
Hotkey, %vblue%, blue, On
Hotkey, %vorange%, orange, On

rebind:
    ; - green
    MsgBox, Press a key for green.
    Input := GetKeyPress(Keys)
    MsgBox, You pressed %Input%
    Hotkey, %vred%, green, Off
    Hotkey, %Input%, green, On
    ; - red
    MsgBox, Press a key for red.
    Input := GetKeyPress(Keys)
    MsgBox, You pressed %Input%
    Hotkey, %vgreen%, red, Off
    Hotkey, %Input%, red, On
    ; - yellow
    MsgBox, Press a key for yellow.
    Input := GetKeyPress(Keys)
    MsgBox, You pressed %Input%
    Hotkey, %vgreen%, yellow, Off
    Hotkey, %Input%, yellow, On
    ; - blue
    MsgBox, Press a key for blue.
    Input := GetKeyPress(Keys)
    MsgBox, You pressed %Input%
    Hotkey, %vgreen%, blue, Off
    Hotkey, %Input%, blue, On
    ; - orange
    MsgBox, Press a key for orange.
    Input := GetKeyPress(Keys)
    MsgBox, You pressed %Input%
    Hotkey, %vgreen%, orange, Off
    Hotkey, %Input%, orange, On

    Gui, Submit, NoHide
return
I am doing a bit of a scuffed method to update the values but blue is the only one that doesn't work, and when I set it to the correct values like vgreen with green and vred with vred it varies on which buttons work. This also happens when I split it into different "rebinds:" as well, so i'm thinking that i'm not updating a value (obviously) correctly cause it has default values that work but doing it correctly makes none of them work. Strange.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Rebinding "Hotkey" Variable problems.

Post by swagfag » 25 Mar 2023, 03:53

its an incomplete script, so i cant troubleshoot what i cant see

Post Reply

Return to “Gaming Help (v1)”