Function for swap on button press

Ask gaming related questions (AHK v1.1 and older)
jas2jas2
Posts: 1
Joined: 23 Sep 2018, 21:15

Function for swap on button press

23 Sep 2018, 21:29

It's my first day on AHK. I am trying to assign a hotkey (0::9) after a key (Mbutton) is pressed a second time. Currently, 0 is assigned to 9 at runtime, regardless of the conditional statement.

What is the correct way to assign a hotkey after another key is pressed first?

Script:

MyVar := "no"

MButton::
if (MyVar = "no")
{
Send, 1
MyVar := "yes"
return
}
else
{
Send, {MButton}
0::9
return
}
User avatar
Onimuru
Posts: 107
Joined: 08 Sep 2018, 18:35
Contact:

Re: Function for swap on button press

24 Sep 2018, 03:02

Like this:

Code: Select all

#SingleInstance Force
SendMode Input

Exit

MButton::Send % ((MyVar := !MyVar) ? "{MButton}" : "1")	;Toggles MyVar between True and False states (all variables are False by default, this is also true if they don't exist) and sends MButton/1.

#If MyVar	;If MyVar is True (has been toggled by MButton):
0::9
#If

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 87 guests