I'm using a simple script, all working fine as I want, but after switch a couple windows or after a while it just stops working.
#InstallKeybdHook
#IfWinActive ahk_exe Figma.exe
$!WheelUp::
Send {Control down}
$^WheelUp::
Send {WheelUp}
SetTimer,ControlUp,-300
Return
$!WheelDown::
Send {Control down}
$^WheelDown::
Send {WheelDown}
SetTimer,ControlUp,-300
Return
ControlUp:
Send {Control up}
Return
#IfWinActive
Is there anything I am missing?
I'm trying to swap keys only when I'm using Figma. I want when I press ALT+mouseUp sent to the software CTLR+MouseUp, and ALT+mouseDown send CTRL+mouseDown.
I want when I press ALT+mouseUp sent to the software CTLR+MouseUp, and ALT+mouseDown send CTRL+mouseDown.
If this's all you need, then wouldn't a simpler code do the job? Do you have any other unspoken needs?
!WheelUp::SendInput, ^{WheelUp}
!WheelDown::SendInput, ^{WheelDown}
The timer can be interrupted by other threads, i.e. another timer subroutine or a hotkey subroutine. When we send keyboard and mouse commands fast, subroutines ControlUp that are constantly being created are constantly being interrupted by newly created timer subroutines and new hotkey subroutine. In the end, these backlogged subroutines, which are postponed running, may not send {Control up} at the timing we expect, which makes script not working as we expect.
Related
i.e. hitting ctrl+s should activate ctrl+s...the below does not work. Neither does the simpler
SendInput, ^s. Goal is to have ctrl+s save current doc and then load another via more code, the saving part never works tho. The bad code, depending on where i put sleep or no sleep, either returns s or shift s (in 1 code editor anyways) or nothing. I basically want a hotkey that mimics itself.
F4::ExitApp
<^s::
send, {lctrl down}
SLEEP 300
SEND s
SLEEP 300
SEND {lctrl up}
return
I would think that the issue your program is running into is that having the ^s send another ^s inside of itself is creating an infinite recursive loop in which nothing is ever able to run past the place you invoke ^s. To prevent this, we can use the $ modifier as so:
$<^s::
SendInput ^s
return
From the relevant section of the Modifier section of the docs:
This is usually only necessary if the script uses the Send command to
send the keys that comprise the hotkey itself, which might otherwise
cause it to trigger itself. The $ prefix forces the keyboard hook to
be used to implement this hotkey, which as a side-effect prevents the
Send command from triggering it. The $ prefix is equivalent to having
specified #UseHook somewhere above the definition of this hotkey.
Edit: it seems to work fine for me even if I remove the $ modifier. Testing the following code shows me there appears to be no problems regarding code execution before, after, or during the SendInput statement.
<^s::
MsgBox no
SendInput, ^s
MsgBox yes
return
Maybe check your version or installation of AHK?
Im trying to make an ahk script to try and simplify a one time use script. Pretty much im running over 1000 commands in a game one after one another .Currently I have something like this. I have all the commands in a single text file just not with any ahk coding.
.waypointadd 1 100234 40 -469
.waypointadd 2 99549 34 5
.waypointadd 3 100615 37 -160
.waypointadd 4 100817 27 -457
.waypointadd 5 100503.5 10.5 -647.5
.waypointadd 6 100494.5 10.5 -625.5
This goes on for a while. Im new to using expressions and such and am pretty much trying to make it to press enter, type the command, then press enter, then go to the next one. I obviously cant do this manually. I have tried using some basic replace expressions and stuff but not really sure how to do this.
In the end i would want it to look like this
send {enter}
send (command 1)
send {enter}
send {enter}
send (command 2)
send {enter}
you could bind it to a key like....
1::
loop, 1 {
send {enter}
send (command 1)
send {enter}
send {enter}
send (command 2)
send {enter}
}
or make a function when you a press a key. lmk if this helps or not
doSomething() {
send {enter}
send (command 1)
send {enter}
send {enter}
send (command 2)
send {enter}
}
1::
doSomething()
You could store all the commands in your clipboard (CTRL+C them) and then loop through all of them:
Loop, Parse, Commands, `n, `r ;split by linefeed, ignore carriage return
{
SendInput, % A_LoopField "{Enter 2}"
Sleep, 1000 ;however long you need
}
Loads of ways to get the commands into your script, I just went with loading them from your clipboard, should be pretty easy convenient to just copy the block of commands you want and then starting the script.
Then there's a parsing loop.
And then SendInput is used to send the current command follow by two presses of Enter.
Alternatively, if your game supports pasting from clipboard, it would be nice to just load your clipboard with whatever you want to send, and then sending a CTRL+V.
If the code with SendInput is going too fast, you can try switching over to normal Send and maybe even using SetKeyDelay to add even more delay between the keypresses.
I'm at a loss here. As soon as I add the LButton hotkey, the Send, {LButton} doesn't seem to work, but they show up in recently executed lines.
Env. Windows 7x64, Disabled Touchpad, AHK v1.1.31.01.
I try to emulate the Wink application (from DebugMode) to capture screenshots for training purposes. For that reason, I want to capture a screenshot just before a mouse click. This looks easy, and I even vaguely remember doing similar mouse hotkeys in the past. However I can't get this to work.
Step 1: I just reduced it to this simple script:
#InstallKeybdHook
#InstallMouseHook
#UseHook
#Persistent
Return
a::
Send, {LButton}
Return
q::
ExitApp
When using this script, I can simulate clicking the Left Mouse Button through the a key. Nothing special.
However as soon as I add either a line with "Hotkey, $LButton, MySendClick", or "$LButton::" the previously working a hotkey no longer works. In the recently executed lines, you can see the "Send, {LButton}" lines, but nothing is being send. Unexpectedly, the a hotkey actually causes the "$LButton::" hotkey to trigger (without it sending {LButton}). When I change the a hotkey to send "RButton" and the $LButton:: to $RButton::, then Send {Click} works perfectly (eventhough the a hotkey should never be able to trigger $RButton::).
Originally I just wanted to have the following HotKey:
$LButton::
SoundBeep, 300, 150 ; For testing only
; Send, ^{PrintScreen} ; To trigger Greenshot in the background
Sleep, 100
Send, {LButton}
Return
I upgraded from AHK v1.1.22.04 to v1.1.31.01. No improvement.
I tried "Click", "sendInput, {LButton}", "Send {Click}", "MouseClick, Left".
I tried "$LButton::", "vk01sc000::", "Hotkey, $LButton, MyClick".
Is this an issue with my specific Windows 7 configuration or an "undocumented AHK feature"?
#InstallKeybdHook
#InstallMouseHook
#UseHook
#Persistent
Return
a::
Send, {LButton}
Return
$LButton::
SoundBeep, 300, 150 ; Should be Send, ^{PrintScreen} ; To trigger Greenshot in the background
MouseClick, Left
Return
q::
ExitApp
In this last test example, When $LButton:: is disabled, the a hotkey works like a charm, but as soon as I enable $LButton::, the a hotkey triggers $LButton:: and no mouse click is being sent to the windows applications.
I would appreciate it when other Windows 7 users could quickly test this issue.
In my experience, using keys that you still want the input to pass through need the Tilde prefix.
https://www.autohotkey.com/docs/Hotkeys.htm#Tilde
~LButton::
SoundBeep, 300, 150 ; Should be Send, ^{PrintScreen} ; To trigger Greenshot in the background
KeyWait, LButton ; Wait for lbutton to be released.
Return
I have a shortcut to open the current running script in a text editor and then save it and close it. Upon closing, how do I update ahk to use the new updated settings?
This is what I have:
IfWinExist, test.ahk ahk_exe notepad.exe
{
WinActivate
Sleep, 100
Send, ^s
Sleep, 200
WinClose
}
else
MsgBox, window not found
app1Open=false
Reload
If you want to restart the script itself (that is, from its own process), use the Reload command.
Otherwise, if you want to restart the script from another process, you have to close it and then run the script again. In this case, you can either kill the script's process and run it again (not nice!). Or you can tell the script to gracefully Reload, for example in one of these two ways:
Inter-process communication: OnMessage() for the receiving process and PostMessage/SendMessage in the sending process
Defining a simple hotkey in your receiving script and sending that hotkey from another process
As MCL mentioned, use Reload. There is no need to close the script. Here is an example:
^!#r:: ; Save and Reload the script with Alt+Ctrl+Win+r
IfWinExist, SciTE4AutoHotKey
{
WinActivate
Sleep, 100
Send, ^s
Sleep, 300
}
Reload
Return
in AutoHotKey
I want to write a script that will press a button once when the right mouse button is held
and press another once its released.
I tried writing something (I used numpad0 instead of mousebutton)
Numpad0::
Send {d}
Numpad0 Up::
Send {u}
but, it keeps sending du all the time, instead of just d and a final u.
why is that?
If you're putting your hotkey command on a different line to where the hotkey is declared you need to use a return statement to end it:
Numpad0::
Send {d}
return
Numpad0 Up::
Send {u}
return
You can also just declare each hotkey on one line without a return if you're not trying to do too much:
Numpad0:: Send {d}
Numpad0 Up:: Send {u}