Code: Select all
Ctrl-Alt-i::
Toggle := !Toggle
loop
{
If not Toggle
break
scrollLock
}
return
Code: Select all
Ctrl-Alt-i::
Toggle := !Toggle
loop
{
If not Toggle
break
scrollLock
}
return
Code: Select all
#NoEnv
^!i::SetTimer, MyLoop, % (Toggle := !Toggle) ? 750 : "Off"
MyLoop:
Send, {ScrollLock}
return
Hey this is a nice way to boost versatility of settimer. Its not clear in docs that u can expand the period parameter like this. Could you please comment on it?Xtra wrote:HTHCode: Select all
#NoEnv ^!i::SetTimer, MyLoop, % (Toggle := !Toggle) ? 750 : "Off" MyLoop: Send, {ScrollLock} return
This is nothing limited to SetTimer - you can use the ternary operator in a lot of cases to replace a simple if-else-comparison:DRocks wrote:Hey this is a nice way to boost versatility of settimer. Its not clear in docs that u can expand the period parameter like this. Could you please comment on it?
(https://autohotkey.com/docs/Variables.htm#operators)docs wrote:?: Ternary operator [v1.0.46+]. This operator is a shorthand replacement for the if-else statement. It evaluates the condition on its left side to determine which of its two branches should become its final result. For example, var := x>y ? 2 : 3 stores 2 in Var if x is greater than y; otherwise it stores 3. To enhance performance, only the winning branch is evaluated (see short-circuit evaluation).
Very interesting and thanks alot for taking timegregster wrote:This is nothing limited to SetTimer - you can use the ternary operator in a lot of cases to replace a simple if-else-comparison:DRocks wrote:Hey this is a nice way to boost versatility of settimer. Its not clear in docs that u can expand the period parameter like this. Could you please comment on it?
(https://autohotkey.com/docs/Variables.htm#operators)docs wrote:?: Ternary operator [v1.0.46+]. This operator is a shorthand replacement for the if-else statement. It evaluates the condition on its left side to determine which of its two branches should become its final result. For example, var := x>y ? 2 : 3 stores 2 in Var if x is greater than y; otherwise it stores 3. To enhance performance, only the winning branch is evaluated (see short-circuit evaluation).
But here it was combined with the possibility of forcing an expression: https://autohotkey.com/docs/Variables.htm#Expressions (at the end of the section)
Users browsing this forum: marypoppins_1, ShatterCoder and 140 guests