Switch + hold key Topic is solved

Ask gaming related questions (AHK v1.1 and older)
overlord132
Posts: 14
Joined: 09 Nov 2015, 18:31

Switch + hold key

Post by overlord132 » 24 Sep 2022, 13:36

Hello guys!

I need help to make a script with switch function in one key and hold function.

My ideia is to do a switch between the keys "V" and "X", keeping these keys pressed each time i switch.
Ex. If i press "=" once, it will activate and hold the key "V". If i press "=" again, it will release the "V" and will to start to hold the "X" key.
Keeping this cycle hold-release every time i press "=".

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

Re: Switch + hold key  Topic is solved

Post by Rohwedder » 25 Sep 2022, 02:41

Hallo,
try:

Code: Select all

=::Send,% GetKeyState("x")?"{x Up}{v Down}":"{v Up}{x Down}"

overlord132
Posts: 14
Joined: 09 Nov 2015, 18:31

Re: Switch + hold key

Post by overlord132 » 27 Sep 2022, 23:08

@Rohwedder
Great job! It works very well.

It's possible to make another key with a function of stop the switch?
And, as a last favor, it would be possible to create another command in which the "X" and "V" keys are released and the "Space" key is pressed while holding the "[' key?

E.x.:
[ {down}:: X,V {up} Space {down}
[ {up}:: X,V {up} Space {up}

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

Re: Switch + hold key

Post by Rohwedder » 28 Sep 2022, 01:23

Then:

Code: Select all

=::Send,% !Switch?(GetKeyState("x")?"{x Up}{v Down}":"{v Up}{x Down}"):"{x Up}{v Up}"
q Up::Send,% (Switch:=!Switch)?"{x Up}{v Up}":""
[::
Send, {x Up}{v Up}{Space Down}
KeyWait, [
Send, {Space Up}
Return
Key Q toggles the xv-switch off/on.

overlord132
Posts: 14
Joined: 09 Nov 2015, 18:31

Re: Switch + hold key

Post by overlord132 » 28 Sep 2022, 16:00

@Rohwedder
all works great!

It has just one problem: the space key is sending only once when I hold "["

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

Re: Switch + hold key

Post by Rohwedder » 29 Sep 2022, 00:54

Then with simulated auto repeat:

Code: Select all

=::Send,% !Switch?(GetKeyState("x")?"{x Up}{v Down}":"{v Up}{x Down}"):"{x Up}{v Up}"
q Up::Send,% (Switch:=!Switch)?"{x Up}{v Up}":""
[::
Send, {x Up}{v Up}
While, GetKeyState("[","P")
{
	Send, {Space Down}
	Sleep, 30
}
Send, {Space Up}
Return

Post Reply

Return to “Gaming Help (v1)”