Help me understand what the syntax of this code means

Get help with using AutoHotkey and its commands and hotkeys
mexican scientist
Posts: 10
Joined: 02 Jul 2020, 21:55

Help me understand what the syntax of this code means

Post by mexican scientist » 20 Sep 2020, 13:27

I have no Idea what the syntax of this code is saying.

Code: Select all

~]::
SetTimer RBracket,% (RBracket:=!RBracket)?12500:"Off"
I was told this works like a loop that repeats a task every 12.5 seconds, but what I don't understand is the ",%" and the "?" used in the code. I read the SetTimer notes and there is no information about this. I want to understand this code so that I can modify it and make a better code; I am trying to make a code that does the following:

~]::
press MButton and wait 12.5 seconds
if ] is pressed again at anytime between the 12.5 second of wait, then press MButton and reset timer (so that the next ~]:: will press MButton and wait 12.5 seconds), However, if ] is not pressed, then wait the whole 12.5 seconds

The code that almost does the job is this:

Code: Select all

~]::
SetTimer RBracket,% (RBracket:=!RBracket)?12500:"Off"
IF !RBracket
	return
RBracket:
	sendinput, {MButton down}
	sleep, 50
	sendinput, {MButton up}
return

User avatar
mikeyww
Posts: 3963
Joined: 09 Sep 2014, 18:38

Re: Help me understand what the syntax of this code means

Post by mikeyww » 20 Sep 2020, 13:34

?: is called a ternary operator. "% " is called a forced expression.

User avatar
Yakshongas
Posts: 591
Joined: 21 Jan 2020, 08:41
Facebook: Yakshongas

Re: Help me understand what the syntax of this code means

Post by Yakshongas » 20 Sep 2020, 17:05

mexican scientist wrote:
20 Sep 2020, 13:27
I have no Idea what the syntax of this code is saying.

Code: Select all

~]::
SetTimer RBracket,% (RBracket:=!RBracket)?12500:"Off"
This is like an If/ else statement but in a single line that switches between the two options using a variable that switches between two states (True & False).

An example here.

Code: Select all

F1::MsgBox, % (Toggle := !Toggle) ? "First Option" : "Second option"
Please mark your topics as solved if you don't need any further help. ✅

Need a little more help? Discord : Yakshongas#9893 🕹

Post Reply

Return to “Ask For Help”