AutoHotKey - Multiply variables not working - autohotkey

I have problems with an AutoHotKey script. When I press F1, the left mouse button is held but A is also pressed. Does anyone know how I can fix this?
#MaxThreadsPerHotkey, 2
Toggle := 0
Toggle2 := 0
F1::
Toggle := !Toggle
If (Toggle){
Click, Down
} else {
Click, Up
}
F2::
Toggle2 := !Toggle2
If (Toggle2){
send {a down}
} else {
send {a up}
}

You need to tell autohotkey that you are done writing the code that should be executed when a hotkey is pressed by putting a Return after the last part you want to execute.
From the docs:
Returns from a subroutine to which execution had previously jumped via
function-call, Gosub, Hotkey activation, GroupActivate, or other
means.
So for your script:
#MaxThreadsPerHotkey, 2
Toggle := 0
Toggle2 := 0
F1::
Toggle := !Toggle
If (Toggle){
Click, Down
} else {
Click, Up
}
return
F2::
Toggle2 := !Toggle2
If (Toggle2){
send {a down}
} else {
send {a up}
}
return

Related

Press in random time range?

I am currently having this code which will press Z every 1.5 seconds after activated by pressing B
toggle := 0
return
b::
toggle := !toggle
if (toggle = 1)
SetTimer, Pressz, 1500
else
SetTimer, Pressz, Off
return
Pressz:
SendInput, z
v::SetTimer, Pressz, 1500
But then I am not sure how to change the SetTimer into random time between 0 to 1500
Please help thanks.
Utilizing the 'Random' function that 0x464e mentioned, and single fire SetTimer routines, I created this
toggle := 0
return
b::
toggle := !toggle
;MsgBox %toggle%
if (toggle){
gosub Routine
}
return
Routine:
if(toggle){
Random, var, -1500, 0
gosub Pressz
SetTimer, Routine, %var%
}
return
Pressz:
SendInput, z
return
v::
toggle=1
gosub Routine
return

AutoHotKey issue with AltTab shortcut

i was trying to create a simple script with AHK to switch between windows (similar to the "recent" button on a samsung mobile) with this code:
XButton2::
Send, {Alt down}{Tab}
Return
the problem is that i don't know how to make the script to release the Alt key when i strike Enter or click the Left mouse button.
Any help please?
XButton2::
AltTabMenu := true ; assign the Boolean value "true" or "1" to this variable
Send, {Alt down}{Tab}
return
; The #If directive creates context-sensitive hotkeys:
#If (AltTabMenu) ; If this variable has the value "true"
; The * prefix fires the hotkey even if extra modifiers (in this case Alt) are being held down
*Enter::
*MButton::
Send {Enter}
Send {Blind}{Alt Up} ; release Alt
MouseCenterInActiveWindow()
AltTabMenu := false
return
~*LButton::
Click
Send {Blind}{Alt Up} ; release Alt
MouseCenterInActiveWindow()
AltTabMenu := false
return
; menu navigation by scrolling the mouse wheel:
*WheelUp:: Send {Right}
*WheelDown:: Send {Left}
#If ; turn off context sensitivity
MouseCenterInActiveWindow(){
WinGetPos,,Y, Width, Height, A ; get active window size
Xcenter := Width/2 ; calculate center of active window
Ycenter := Height/2
MouseMove, Xcenter, Ycenter, 0
}

AHK, not working as expected

trying to make a toggle-able loop, seems to be not sending e at all, help please?
myvar := false
k::
myvar := true ? false : true
return
while (myvar)
{
Send, e
Sleep 100
}
Here is my suggestion:
k::SetTimer, SendLetterE, % (Toggle:=!Toggle) ? 100 : "Off"
SendLetterE() {
Send, e
}
You can assign another key to pause / resume. In this case k will toggle and F12 will run indefinitely (so just use k to toggle).
k::
Hotkey, F12, toggle
return
F12::
while(true)
{
Send, e
Sleep 100
}
Could also try Loop instead of while(true)
k::
pause, toggle
F12::
Loop,
{
Send e
Sleep, 100
}
return
referenced from AutoHotkey forum.

Can someone help me with this AHK Script

I want this Autohotkey script to press the spacebar automatically with a toggle option so i dont have to hold the spacebar all the time. The toggle key should be the middle mouse button. Could you please write it correctly for me? Because the toggle part I found doesn't seem to work. Thanks in advance CptPrice :D
Main script:
*~$Space::
Sleep 100
Loop
{
GetKeyState, SpaceState, Space, P
If SpaceState = U
break
Sleep 5
Send, {Blind}{Space}
}
Toggle-part:
#MaxThreadsPerHotkey 2
MButton::
if (toggle := !toggle) {
; on
} else {
; off
}
return
toggle := false
return
MButton:: toggle := !toggle
#If toggle
#MaxThreadsPerHotkey 2
*~$Space::
Sleep 100
Loop
{
Sleep 5
Send, {Blind}{Space}
if (!toggle) ; Press MButton to break
break
}
return
#If

Send hotkeys own default behavior

How can I send a keys default (from hardware) behavior in its own key definition. I mean this code:
vcerc = 0
+c::
vcerc := !vcerc
Return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
kkey = 0
$k::
if vcerc {
kkey := !kkey
if kkey
SendInput {k down}
else
SendInput {k up}
}
else {
Send, K
}
Return
In the end part Send, K It sends the word K. I am in a multi language environment which means if I switch to the other, This key still sends K rather than sending the one that is for the second language (assume ن).
How can I make this send the default? (From hardware with no matter what the language is)
Two things that seem off to me: 1) Your initial kkey declaration will never get hit since it falls after a hotkey (and a return). Declare your variables at the top. 2) if kkey is true, your script has it holding down the k button indefinitely. Is this expected? 3) Your only looking for lowercase k's but sending uppercase k's. Is this expected?
At any rate, this example should point you in the right direction.
vcerc = 0
kkey = 0
+c::
vcerc := !vcerc
return
$k::
{
if (vcerc) {
kkey := !kkey
if (kkey) {
msgbox, k down ; SendInput {k down}
} else {
msgbox, k up ; SendInput {k up}
}
} else {
Send, K
}
}