I want to change Ctrl + Shift + Z to Ctrl + Y so I made the below script:
^+z::^y
This script sends Ctrl + Shift + Y, which isn't quite what I want, so I changed it to:
^+z::
KeyWait LShift
Send ^y
Return
It works, but it causes kind of delay because I should up LShift in order to execute Send line.
Is there any way to avoid this delay?
Try
^+z::
Send {Shift up}
Send ^y
Return
This should programmatically release the Shift key before Sending the ^y input.
Related
I have two AutoHotkey scripts that enable the use of the Ctrl key on both sides of my laptop's keyboard:
Map Caps Lock to (left) Ctrl:
SetCapsLockState, Off
CapsLock::LCtrl
Map Enter to (right) Ctrl when pressed down; otherwise (if no timeout) send Enter:
Enter::RCtrl
~Enter Up::Send % "{RCtrl up}" (A_PriorKey = "Enter" ? "{Enter}" : "")
The two scripts work perfectly with almost no edge cases.
However, I'm unable to trigger Ctrl + Enter, which is a shortcut that I usually use to open a new line on my text editor. Pressing down Caps Lock and hitting Enter, nothing happens. Even if I press down (left)Ctrl (the real key) and hit Enter, nothing happens as well.
What should I do to enable both scripts to work together in order to enable Ctrl + Enter?
I managed to solve the problem in two steps:
Natively map CapsLock to Control. AutoHotkey thinks my CapsLock key is indeed the Control key, which exempts me from handling weird CapsLock on/off edge cases within AutoHotkey.
Use the following script to map Enter as dual-function RCtrl/Enter:
LShift & Enter Up::
GetKeyState, state, Shift
if (A_PriorKey = "Enter" and state = "D") {
Send +{Enter}
}
Send {LCtrl Up}{RCtrl Up}
Return
LCtrl & Enter Up::
GetKeyState, state, Control
if (A_PriorKey = "Enter" and state = "D") {
Send ^{Enter}
}
Send {LCtrl Up}{RCtrl Up}
Return
LAlt & Enter Up::
GetKeyState, state, Alt
if (A_PriorKey = "Enter" and state = "D") {
Send !{Enter}
}
Send {LCtrl Up}{RCtrl Up}
Send {LAlt Up}{RAlt Up}
Return
Enter::RCtrl
~Enter Up::
Send % "{RCtrl up}" ((A_PriorKey = "Enter") ? "{Enter}" : "")
It's super exciting because it works very well! The modifier dance between CapsLock and Enter as symmetric control keys is perfect and I can seamlessly alternate between both sides without nasty edge cases, unexpected modifier presses, releases, or {Enter} presses. The order of the declarations is very important for that to work; the edge cases must come first.
However, as you can see, it is necessary to explicitly handle Alt + Enter, Ctrl + Enter, and Shift + Enter. If I ever need Ctrl + Alt + Enter, I will need to handle that as well.
I wonder if there's a better way to make that work without having to define these additional mappings.
I've tryied on Libreoffice Writter, where CTRL+ENTER go to the next page..
The above code worked fine.
Just added ~ before Enter::RCtrl to not block native function from Enter key.
SetCapsLockState, Off
CapsLock::LCtrl
~Enter::RCtrl
~Enter Up:: Send % "{RCtrl up}" (A_PriorKey = "Enter" ? "{Enter}" : "")
P.S:
And i think you may use only one script with both instructions, instead of using one script for each..
XButton2 + RButton::
Send, Hello World
return
Apparently this is an invalid hotkey but I don't know why.
In AutoHotkey, we use the & operator when we want multiple keys pressed together to trigger a hotkey. In AHK, the + operator instead stands for the Shift key.
Solution:
XButton2 & RButton::
Send, Hello World
return
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
I've got a keyboard without the Win key (a legendary Model M!), so I want to bind it to ctrl + esc.
I tried those things, but that doesn't work -_-
LCtrl & Escape::LWin
or
LCtrl & Escape::
Send {LWin}
return
If I simply do:
Escape::LWin
or
Escape::
Send {LWin}
return
It's OK...
I also got another function that works OK like this:
^!F2::Send {Volume_Up 100}
So right now, can't figure what's wrong... Probably the misuse with the "&"?
Any idea?
Thank you!
After answer 1: I found this solution if I want to use the win key for combination (Win + e, Win + d, etc.):
^Esc::
KeyWait Ctrl ;wait until Ctrl is up
Send {LWin Down} ;send left Windows key down
sleep, 500
Send {LWin Up} ;send left Windows key up
Return
That way, when I depress ctrl, I've got 500ms to type the 2nd key.
The problem is that you if you press Ctrl+Esc, then
LWin is sent by AHK, but you are still holding down Ctrl so the result of this 'cooperation' is Ctrl+LWin which is ignored by Windows.
Solution:
^Esc::
KeyWait Ctrl ;wait until Ctrl is up
Send {LWin} ;send left Windows key
Return
I have an old IBM Model M from 1994. It's awesome, but it doesn't have a Windows key. I'd like to use AutoHotkey to map the combination of Ctrl + Alt to simulate the Windows key in order to take advantage of the default Windows shortcuts. Here's what I have:
LCtrl & LAlt :: Send {LWin}
It was suggested that maybe windows is overriding the Ctrl + Alt combo, so I also tried:
~Alt & Space :: Send {LWin}
Neither of these work. I'd at least like to be able to open the Start Menu from the keyboard (Ctrl + Esc is too awkward.)
It seems the windows key is not working as long as either ctrl or alt is pressed. The following script works for me:
<^LAlt::
KeyWait Alt
KeyWait Ctrl
Send {RWin}
return
<!LCtrl::
KeyWait Alt
KeyWait Ctrl
Send {RWin}
return
You can press the left Ctrl and left alt in any order, and when you release both, the windows key is generated. This way you will not be able to send combination like Windows-E. If you want that too, you can do something like:
<^<!e::
KeyWait Alt
KeyWait Ctrl
Send {RWin down}e{RWin up}
return
<^<!space::
KeyWait Alt
KeyWait Ctrl
Send {RWin}
return
Now press leftctrl-leftalt-e to genereate windows-e, and press leftctrl-leftalt-space for just the windows key.
I'm also using an IBM Model M. I've mapped RCtrl to the RWin key using KeyTweak (in Windows 7 and XP).
You can get KeyTweak here: KeyTweak homepage
(you can edit directly your registry but it's much easier to use the above program).
With this approach you can continue to use Win+R, Win+Tab (in Windows 7), Win+E, etc. and your Autohotkey scripts will also detect your RCtrl keypresses as RWin.
Try this:
Ctrl & Q::send {LWin}
Someone suggested that I make my comment an answer.
I did very similar to what wimh did above, but I removed the KeyWait commands. Normal keyboard hotkeys don't wait until you have all of your fingers lifted off of the keys, you can press the hotkey combination and then hold the keys down, and have the action still occur. The >^>! and <^<! make the command work with either the left or the right Alt and Ctrl keys.
; Open explorer
>^>!e::
Send #e
return
<^<!e::
Send #e
return
; Lock workstation, #L and downLup don't work
>^>!L::
DllCall("LockWorkStation")
return
<^<!L::
DllCall("LockWorkStation")
return
; Run dialog
<^<!r::
Send {RWin down}r{RWin up}
return
>^>!r::
Send {RWin down}r{RWin up}
return
I'm not sure why some key combinations you can use #, but others like the Run dialog require you to RWin down, press r, then RWin up. This must be a quirk with Windows.
I've uploaded my autohotkey.ahk file to Github, if anyone is interested!