AutoHotKey Invalid Hotkey XButton2 + RButton:: - autohotkey

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

Related

Invalid hotkey: Ctrl & CapsLock & L

To map CapsLock to Esc if pressed alone, and use it as a modifier key otherwise, I use this script:
#InstallKeybdHook
SetCapsLockState AlwaysOff
CapsLock::Send {esc}
CapsLock & h::Left
CapsLock & j::Down
CapsLock & k::Up
CapsLock & l::Right
return
To move around virtual desktops in Windows, I wanted to now map Ctrl & CapsLock & l::^#Right. Unfortunately this is not possible and gives an error: Invalid hotkey. Does anybody know why?
Instead of remapping I'd use the Send command to define new hotkeys.
A remapping is not a hotkey. A remapping is two hotkeys (key-down and key-up) with each having the wildcard modifier, as shown in the documentation.
Combinations of three or more keys (Ctrl & CapsLock & l) are not supported.
Or try it this way:
#InstallKeybdHook
SetCapsLockState AlwaysOff
CapsLock::Send {esc}
CapsLock & h::Send {Left}
CapsLock & j::Send {Down}
CapsLock & k::Send {Up}
CapsLock & l::
If GetKeyState("Ctrl", "P")
SendEvent {LWin down}{LCtrl down}{Right down}{LWin up}{LCtrl up}{Right up} ; switch to next virtual desktop
else
Send {Right}
return

Make CAPSLOCK work properly when single-, double-, and combo-pressed

I want to write an AutoHotKey script on Windows 10 that gives CAPSLOCK more functionality. My goals with CAPSLOCK are three-fold:
When single-pressed, CAPSLOCK works as usual.
When double-pressed (pressed twice in a short time), CAPSLOCK fires an ESC key. The status/light of CAPSLOCK should remain the same as before, but I am okay if the light went on and off, or off and on.
When CAPSLOCK are held down, in combination with JKLI, CAPSLOCK + JKLI will function as arrow keys (left, down, right, up). Like in goal 2, the status/light of CAPSLOCK should remain the same as before. (I am okay if the light went on and off in the process, so long the terminal status is correct).
If I only needed goal #1 and goal #3, the following script would work just fine.
CapsLock & J::Send {Left}
CapsLock & K::Send {Down}
CapsLock & L::Send {Right}
CapsLock & I::Send {Up}
However, now I want to achieve goal #2 as well, and added some more lines before it, as follows
~CapsLock::
KeyWait, CapsLock
KeyWait, CapsLock, D T0.2
if not ErrorLevel
Send {Escape}
Return
CapsLock & J::Send {Left}
CapsLock & K::Send {Down}
CapsLock & L::Send {Right}
CapsLock & I::Send {Up}
Now I am having the problem: goal #1 and goal #2 are achieved, but goal #3 is not. The status/light of CAPSLOCK would change after say I pressed CAPSLOCK + L. This is not what I want -- I want holding down CAPSLOCK and pressing L to move cursor to the right, and I want this behavior to have no effect on the status of CAPSLOCK.
Please let me know how to achieve my three goals with CAPSLOCK using AutoHotKey. Any help is much appreciated!
By the way, I am working on a Lenovo Thinkpad T model produced in 2016.
You need a timer to restore the CapsLock state after it has been changed in a combination:
Capslock::
If (A_PriorHotKey = "~Capslock Up" AND A_TimeSincePriorHotkey < 400 AND A_TimeSincePriorHotkey > 50) ; double-press
Send, {Esc}
SetTimer, RestoreCapslockState, 50
return
~Capslock Up:: return ; The tilde prefix (~) prevents AHK from blocking the key-down/up events
CapsLock & J::Send {Left}
CapsLock & K::Send {Down}
CapsLock & L::Send {Right}
CapsLock & I::Send {Up}
RestoreCapslockState:
KeyWait, Capslock ; wait for Capslock to be released
SetTimer, RestoreCapslockState, OFF
If (A_PriorKey != "Capslock")
SetCapsLockState % !GetKeyState("CapsLock", "T") ; Toggles CapsLock to its opposite state, requires [v1.1.30+]
return
https://www.autohotkey.com/docs/commands/SetTimer.htm
https://www.autohotkey.com/docs/commands/SetNumScrollCapsLockState.htm#ex2

CTRL key is held down in AutoHotKey

Pressing the CTRL+Numpad 7 key, it displays the text I want, but the CTRL key remains pressed.
How do I prevent it from being pressed after executing the command?
My AutoHotKey code is something like this
Ctrl & Numpad7::
SendInput `
(
some text
multiline
)
return
I had the same problem and I fixed it with this something like this :
!Crtl Up:: send {Ctrl Down}
try this in the end of the script(the line after return).

Autohotkey: binding win key

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

Using AutoHotKey scripting language is it possible to swap Alt and Ctrl keys and also retain native AltTab key behaviour?

Currently I must Ctrl & Tab to perform a traditional AltTab.
I've already swapped my Alt and Ctrl keys. However, I still want to be able to AltTab traditionally
This is what I have so far:
LCtrl::Alt
Alt::LCtrl
LCtrl & Tab::AltTab
LCtrl & Tab::Send {Alt Down}{Tab}{Alt Up}
Is the simple answer and will switch between the last 2 open windows.
If you want proper functionality, you'll have to read:
http://www.autohotkey.com/docs/commands/GetKeyState.htm
and use it in conjuction with
GetKeyState, OutputVar, LCtrl
If OutputVar = "D"
Send {Tab}
etc
This is works for me
LControl & Tab::AltTab