I read a lot already about the instruct3ions, but the documentation is just too much, i don ty know when im done reading, and i still havent gotten to the point where i foudn the instruction to where i can do what i wanted to do.
I want a key toggle that toggles hold right mouse click and a toggle for clicking the key 'E' repeatively.
I hope someone can help.
thx
How to toggle a key?
Re: How to toggle a key?
There isn't an "instruction" for everything you might want to do with the language. It's up to the user to put the code together from the basic building blocks of the language to accomplish what you want it to do. In the case of a toggle, it is accomplished by assigning a variable one value or another and having a section of code execute (or not) depending on the value of that variable.
Using very basic and easy to understand language elements, a toggle might be accomplished like this:
Then you might learn on your own or by seeing others implement a toggle that it is more efficiently accomplished like this:
To do what you asked about:
Using very basic and easy to understand language elements, a toggle might be accomplished like this:
Code: Select all
#Requires AutoHotkey v2.0
F1:: {
static toggle := 0
if (toggle = 1)
toggle := 0
else
toggle := 1
ToolTip toggle
}
Then you might learn on your own or by seeing others implement a toggle that it is more efficiently accomplished like this:
Code: Select all
#Requires AutoHotkey v2.0
F1:: {
static toggle := 0
ToolTip toggle := !toggle
}
To do what you asked about:
Code: Select all
#Requires AutoHotkey v2.0
#MaxThreadsPerHotkey 2
F1:: {
static toggle := 0
Click 'R ' ((toggle := !toggle) ? 'down' : 'up')
}
F2:: {
static toggle := 0
toggle := !toggle
while toggle {
Send "e"
Sleep 50
}
}
Re: How to toggle a key?
thanks, i was trying to unde5rstand the code.
why is it click 'r ' and not click, Right?
static u set it to 0, meaning u turn f1 off by default>?, and u then execute the click function by click 'r '. whats in that brace is a bit confusing.
why is it click 'r ' and not click, Right?
static u set it to 0, meaning u turn f1 off by default>?, and u then execute the click function by click 'r '. whats in that brace is a bit confusing.
Re: How to toggle a key?
also, when i hold the f1 key instead of just tapping it , the loop isnt stoppable anymore
Re: How to toggle a key?
Click, Right (or Click, R) is v1 syntax. Are using v2? You posted in the v2 section. That explains both the quotes and the lack of comma. The reason for the space after the R is that it is followed by down or up. Without the space, when concatenated together, it would become Rdown or Rup.
It just means it starts with a value of 0, so the first time it’s toggled, it becomes 1.
It’s the ternary operator that is a shorthand for if/else. If the condition is true (meaning toggle has the value 1), then the result is down, otherwise it is up.
I believe you said you wanted to toggle each time it’s pressed. I didn’t see where you described wanting it to do something else when held down. The thread topic is about how to toggle using a key. If you want to ask a different question, please start a new thread.
Re: How to toggle a key?
((toggle := !toggle)
can u tell me what is !toggle?
can u tell me what is !toggle?
Re: How to toggle a key?
It’s just a variable. It could have any name.
Re: How to toggle a key?
ok. is there a way to actiate the key only after I release it? bc i might press a bit longer
Re: How to toggle a key?
As described in the Hotkeys documentation: F1 Up::.
Re: How to toggle a key?
hello, instead of right mouse click I would also like to toggle space button:
[Mod edit: [code][/code] tags added. Please use them yourself when posting code!]
I tried adding 'space' but instead i believe it types it out.
Is the name wrong:?
Code: Select all
!3:: {
static toggle := 0
Click 'space' ((toggle := !toggle) ? 'down' : 'up')
SoundBeep 1500
}
I tried adding 'space' but instead i believe it types it out.
Is the name wrong:?
- DuckingQuack
- Posts: 222
- Joined: 20 Jan 2023, 18:20
Re: How to toggle a key?
Click is almost exclusively for mouse, you'll need Send for the space bar.
https://www.autohotkey.com/docs/v2/lib/Send.htm
https://www.autohotkey.com/docs/v2/lib/Send.htm
Best of Luck,
The Duck
The Duck
Re: How to toggle a key?
I tried using brackets but still bad results:
Code: Select all
!3:: {
static toggle := 0
Send '{Space}' ((toggle := !toggle) ? 'down' : 'up')
SoundBeep 1500
}
Re: How to toggle a key?
Code: Select all
!3::
{
Static toggle := 0
Send( "{" ( toggle := !toggle ? "Space down" : "Space up" ) "}" ) ; which means {Space down} or {Space up}, depends on toggle value
SoundBeep(1500)
}
All the people here are just like you, but not telepaths. Be more clear - which button, or combination of buttons, do you want to use as a toggler ?
Last edited by vmech on 19 Nov 2023, 10:27, edited 1 time in total.
Please post your script code inside [code] ... [/code] block. Thank you.
Re: How to toggle a key?
I realize now you were likely asking about the ! that precedes the variable toggle. It is a symbol that can be used in place of the operator not, which means to apply the logical opposite. So when the result is True or 1, then applying not or ! makes it False or 0, and vice-versa. So when the variable toggle contains the value 0 (which is the same as False), then toggle := !toggle assigns 1 (or True) to it. And the if the value was 1, it assigns it the value of 0.
Re: How to toggle a key?
@boiler
Now try to explain in the same way what this expression means toggle ^= 1
Now try to explain in the same way what this expression means toggle ^= 1
Code: Select all
0 := !1 ; 0 != 1
1 := !0 ; 1 != 0
Please post your script code inside [code] ... [/code] block. Thank you.
Re: How to toggle a key?
The operator ^ is exclusive-or (xor), which has the result for a value when xor-ed with 1 of the opposite of the original value from 0 to 1 or vice-versa. The assignment operator ^= means to perform the operation on the contents of the variable and assign the result back to the same variable, so toggle ^= 1 will assign toggle the value 1 if it originally contained 0 and 0 if it originally contained 1.
Re: How to toggle a key?
@boiler
Thank you, but the proposal was rhetorical, just to freshen up this evening and this boring topic a little
Thank you, but the proposal was rhetorical, just to freshen up this evening and this boring topic a little
Please post your script code inside [code] ... [/code] block. Thank you.
Re: How to toggle a key?
I assumed you knew the answer, but I didn't know why you asked it other than to challenge me or something. Maybe make it more obvious that it's rhetorical in the future so people don't take time answering a question asked of them that no one wanted an answer to.
- DuckingQuack
- Posts: 222
- Joined: 20 Jan 2023, 18:20
Re: How to toggle a key?
@vmech Thanks for asking the (rhetorical) question.
@boiler Thanks for answering the question because I saw this used and was stumped as to what the comparison was using to compare but your explanation made it wonderfully clear.
@boiler Thanks for answering the question because I saw this used and was stumped as to what the comparison was using to compare but your explanation made it wonderfully clear.
Best of Luck,
The Duck
The Duck
Re: How to toggle a key?
Glad to hear it!DuckingQuack wrote: ↑ @boiler Thanks for answering the question because I saw this used and was stumped as to what the comparison was using to compare but your explanation made it wonderfully clear.
Who is online
Users browsing this forum: DavidP, FanaticGuru, Google [Bot], TomDonovan and 112 guests