Hi. I'm very VERY new to this, and i need a little help.
I want to press one button, this instance F8. The first time i press it, to do #tab, second time i press it !tab.
Can anyone help? Thank you in advance!
2 actions for one key Topic is solved
-
- Posts: 4
- Joined: 17 Nov 2017, 04:31
- Delta Pythagorean
- Posts: 627
- Joined: 13 Feb 2017, 13:44
- Location: Somewhere in the US
- Contact:
Re: 2 actions for one key
Code: Select all
F8::
SendInput, % (Times = 1) "#{Tab}" : "!{Tab}"
Times++
Return
[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat
-
- Posts: 4
- Joined: 17 Nov 2017, 04:31
Re: 2 actions for one key
"Error: A":" is missing its "?"Delta Pythagorean wrote:Code: Select all
F8:: SendInput, % (Times = 1) "#{Tab}" : "!{Tab}" Times++ Return
Line#
002: Return
---> 003: SendInput, % (Times = 1) "#{Tab}" : "!{Tab}"
004: Times += 1
005: Return
006: Exit
The Program will exit."
Help?
Re: 2 actions for one key Topic is solved
So what Delta is doing is called ternary. To correct their code, it would be:
However, this will only produce #{Tab} on the second press of F8; the first will be !{Tab} and all other F8s after will be !{Tab} because Times will always be greater than 1.
To alternate, the variables Times should be changing between two values. A great way to do that is with the logical-not operator ! -- it changes true (1) to false (0) and false (0) to true (1).
I would do it this way, without ternary. And I'll show ternary after this.
Ternary:
You can even consolidate the expression into a single line like this:
Code: Select all
F8::
SendInput, % (Times = 1) ? "#{Tab}" : "!{Tab}"
Times++
Return
To alternate, the variables Times should be changing between two values. A great way to do that is with the logical-not operator ! -- it changes true (1) to false (0) and false (0) to true (1).
I would do it this way, without ternary. And I'll show ternary after this.
Code: Select all
F8::
toggle:=!toggle ; custom variable, you can name it bird or coin or whatever you'd like
If toggle ; if toggle is true or "1"
Send #{Tab}
else
Send !{Tab}
return
Code: Select all
F8::
toggle:=!toggle
Send % (toggle) ? "#{Tab}" : "!{Tab}"
return
Code: Select all
F8::Send % (toggle:=!toggle) ? "#{Tab}" : "!{Tab}"
-
- Posts: 4
- Joined: 17 Nov 2017, 04:31
Re: 2 actions for one key
[quote="Exaskryz"]So what Delta is doing is called ternary. To correct their code, it would be:
However, this will only produce #{Tab} on the second press of F8; the first will be !{Tab} and all other F8s after will be !{Tab} because Times will always be greater than 1.
To alternate, the variables Times should be changing between two values. A great way to do that is with the logical-not operator ! -- it changes true (1) to false (0) and false (0) to true (1).
I would do it this way, without ternary. And I'll show ternary after this.
Ternary:
You can even consolidate the expression into a single line like this:
[/quote]
Thank you very much!
Code: Select all
F8::
SendInput, % (Times = 1) ? "#{Tab}" : "!{Tab}"
Times++
Return
To alternate, the variables Times should be changing between two values. A great way to do that is with the logical-not operator ! -- it changes true (1) to false (0) and false (0) to true (1).
I would do it this way, without ternary. And I'll show ternary after this.
Code: Select all
F8::
toggle:=!toggle ; custom variable, you can name it bird or coin or whatever you'd like
If toggle ; if toggle is true or "1"
Send #{Tab}
else
Send !{Tab}
return
Code: Select all
F8::
toggle:=!toggle
Send % (toggle) ? "#{Tab}" : "!{Tab}"
return
Code: Select all
F8::Send % (toggle:=!toggle) ? "#{Tab}" : "!{Tab}"
Thank you very much!
Who is online
Users browsing this forum: doodles333 and 347 guests