I want to write an AutoHotkey script which loop a key X number of times.
For example, here's is a script which overwrites the function of ENTER key with function of F2 key in File Explorer.
#IfWinActive ahk_class CabinetWClass
Enter::
Send, {F2}
#IfWinActive ahk_class CabinetWClass
Enter::
Send, {ENTER}
#IfWinActive
The goal is to press ENTER to rename a select file, and then press ENTER to confirm the rename. Pressing ENTER on the same file that have just been renamed should send F2 key again (In case there is typo error).
Currently the second block doesn't work as I'm sending the same key, how to fix this?
The KeyWait command is your friend in this case.
There is still room to improve on how you handle the second Enter
#IfWinActive ahk_class CabinetWClass
$Enter::
sleep,100 ; giving time to detect the first Enter
Send, {F2}
Keywait, Enter, T5 D ; wait 5 seconds for the Enter to be pressed down
If (ErrorLevel == 0)
{
Send, {Enter}
sleep 200
Send, {F2}
}
else
{
traytip, , timeout ; Enter was not pressed down in 5 seconds
}
return
Basically, it appears you're trying to assign different tasks to the same hotkey and due to this being done seperately ahk is selecting one of the tasks and running with that task and only that task. If loops can be used within hotkeys, so I would suggest using this to rotate between the two expected outcomes. Please see example below:
temp:= 1
enter::
if(temp==1)
{
Send, {ENTER}
temp:=2
}
else if(temp==2)
{
Send, {F2}
temp:=1
}
return
1::
Temp:=1
return
2::
temp:=2
return
^x::ExitApp
I also added in hotkeys for 1/2 to allow you to manually decide the outcome rather than it being specifically assigned in the case of any issues.
Oh, and ctrl+x to close the macro.
You're trying to rebind the enter key twice.
Rebinding a key is like saying "When I press this key, do this:" - in this case it's under an #IfWinActive so it's more like "When this window is open and I press this key..."
When you break that down you have "When I press enter - press F2" as well as "When I press enter, press enter"
What you're wanting to achieve is make the rebind conditional - i.e. it only sends F2 under certain conditions.
It's hard to know how to help without more context. Is there any reason you can't use a different key combination? Like Ctrl + Shift + Enter?
Something like:
+^Enter::send, {F2}
Related
After a month of trial and error, I've finally found a solution!
How to remap Middle mouse button something else?
If you don't have a three-button mouse, this is a must-have for blender (esp. Laptop)
I'm aware of "emulate 3 button mouse" in Preference>>Input.
But if you check that option then you won't be able to 'Select loop'
which uses ALT leftClick.
What if you could remap Mbutton to any other key you rarely use?
Yes you can!
Nice to see that you tried it yourself.
But here's how a context sensitive remap is actually done:
#IfWinActive ahk_class GHOST_WindowClass
LWin::MButton
#IfWinActive
This script will allow you to remap Mbutton with other key, such as LeftWin.
;~--------------------------------------------------------------------------------------
#IfWinActive ahk_class GHOST_WindowClass ; Blender's class
$LWin:: ; "$" this allows to send the trigger key in a working script***
loop
{
if getkeystate("LWin", "p") ; if a button is Physically held down by the user.
{
send, {MButton DOWN}
}
else
{
send, {MButton UP}
;~ MsgBox, Blender is active ; You dont need this.
return
}
}
#IfWinNotActive ahk_class GHOST_WindowClass ; Other than blender (I'm aware of other methods, but this works for me!)
Send, {LWin} ; *** like here I'm able to use Left Win again without triggering the script.
;~ MsgBox,Blender isnt active ;; You dont need this.
return
;~ --------------------------------------------------------------------------------------
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
Hi im trying to make an AHK Script that sends a button press twice, once when i hold the button down and the second time when i release the button on my keyboard. So far i've only figured out the opposite of making any button a toggle, however that doesn't really help me D: any help appreciated!
The $-prefix prevents the hotkey from triggering itself, because it forces the keyboard hook to be used.
$a::
SendInput, a
KeyWait, a ; wait for the key to be released
SendInput, a
return
For more than one keys, you can use:
#NoEnv
#SingleInstance Force
SendMode Input
#InstallkeybdHook
#UseHook ; prevents the keys from triggering itself
keys := ["a","b","c","d","1","2","3","4"] ; ....
for each, key in keys
hotkey, %key%, send_key_twice, on
return
send_key_twice:
Send, %A_ThisHotkey%
KeyWait, %A_ThisHotkey% ; wait for the key to be released
Send, %A_ThisHotkey%
return
This is my slightly modified version of kidmar's script from AHK forums.
The script should change Backspace key behaviour, i.e. when we press Backspace in Windows Explorer, it works like Alt-Up (we go up one level in files hierarchy).
For some reason it doesn't work. How it should be fixed?
FunBackspaceExplorer()
{
IfWinActive, ahk_class CabinetWClass
{
ControlGetFocus, focused, A
IfNotInString, focused, "Edit" ; Return true only if current control isn't an edit control
return 1
}
return 0
}
#If, FunBackspaceExplorer() ; Backspace hotkey exists only if all conditions are met
Backspace:: SendInput, !{Up}
#If
(There are another working solutions for this task, but I'm interseted in this one).
Your version works on my system, if I use:
#If, FunBackspaceExplorer() ; Backspace hotkey exists only if all conditions are met
Backspace::
SetKeyDelay 10,1000
SendEvent {Alt down}{Up down}{Alt Up}{Up Up}
return
#If
SetKeyDelay inserts a delay between a down event and up event for a send, or a delay after sending keys.
It does not work with SendInput.
I use this hotkey to close the current Window :
:*:xx::
Send, {Alt Down}{Sleep 100}{f4 Down}{Alt Up}{f4 Up}
return ;
How can the script be amended so that the characters xx are not sent to display but are still registered by autohotkeys ? In other words if focus is within open editor do not display the xx characters but still fire the commands associated with the xx keys.
You can't do it with a Hotstring but you would have have to use a Hotkey and check for a double key press. A regular key like x might not be the most useful as it will most likely always get in the way of your regular typing as you want to block the x being sent. An example with Ctrl:
~Ctrl::
KeyWait, Ctrl ; wait for Ctrl to be released
KeyWait, Ctrl, D T0.2 ; and pressed again within 0.2 seconds
if ErrorLevel ; timed-out (only a single press)
MsgBox single
else
MsgBox double
return
The above code comes from here http://www.autohotkey.com/board/topic/23224-resolved-catch-a-double-press-click/#entry150299 and you will also find an example (no 4) on the KeyWait doc http://ahkscript.org/docs/commands/KeyWait.htm