I would like to hold
alt + spacebar + U for the up key
alt + spacebar + H for the left arrow key
alt + spacebar + J for the right arrow key
alt +spacebar + N for the down arrow
is this possible to do with AutoHotkey?
Hello and welcome to AutoHotkey,
you might want to have a look at the basic introduction to the heart of AHK, Hotkeys:
https://www.autohotkey.com/docs/Hotkeys.htm
Configuring hotkeys which do nothing but send another key is fairly simple. For example, alt + spacebar for the up key could be translated into
!Space::
send {up}
return
(note that alt is a modifier and can be written as !)
or short form:
!Space::send {up}
spacebar + U for the up key would be Space & U::send {up}.
But you are seeking for 2 keys PLUS a modifier (alt). For a hotkeylabel triggered by more than just two keys (alt + space + u), you'll need a workaround:
!Space:: ; once alt + space was pressed, ...
while(getKeyState("alt") || getKeyState("space") || getKeyState("u")) { ; ... while either of these is being pressed down, ...
hotKey, *u, altSpaceU, ON ; u should now send {up}
}
hotKey, *u, altSpaceU, OFF
return
altSpaceU: ; note: this is a label, no hotkey
send {up}
return
Please, don't be undeterred by this. AutoHotkey is actually quite powerful and easy to learn. Sadly, (afaik) this is the only working way to solve more-than-two-key-hotkeys.
EDIT
jesus why didnt anybody tell me..
#if getkeystate("alt")
!space::send {up}
#if
is obviously a way better solution
this was the solution
!Space::
send {up}
return
Related
I try to do a shortcut of Ctrl+f+j so that the Ctrl+j will make j a left arrow, and the combination of f will make it a Ctrl (d should work the same with shift), so Ctrl+f+j will be considered as Ctrl+Left Arrow.
I've succeeded in making it work, but after I release the keys, f and d stuck and I can not return to normal mode.
I have the following code:
CapsLock & j::
{
Send, {blind}{Left}
return
f::Ctrl
d::Shift
return
}
CapsLock & l::
{
Send, {blind}{Right}
return
f::Ctrl
d::Shift
return
}
CapsLock up::
{
Send {Ctrl Up}
Send {Shift Up}
return
}
this works well until I release the l key because the d and f keys can not be used afterward. Any ideas why? I just can't use them regularly They keep function as Ctrl and Shift
The solution was to separate the combinations. Turns out ahk does not support nested hotkeys, and doing that messes the releases of the keys. The following code solved my problem.
CapsLock & l::Send, {blind}{Right}
CapsLock & j::Send, {blind}{Left}
CapsLock & f::Ctrl
CapsLock & d::Shift
I'd like to use AutoHotKey to remap:
RAlt::Volume_Down
RCtrl::Volume_Up
RAlt & RCtrl::SendInput {Volume_Mute}
While Vol up works fine with the script as above, vol down is non-repeating & mute only works if the buttons are pressed as Alt,Ctrl (not Ctrl,Alt). I understand why, I just haven't been able to come up with a solution. I can map either volume up/down or mute - but if I try to do both, the behavior is always finicky. I think what I need is something to the effect of:
if GetKeyState("RAlt") and GetKeyState("RCtrl")
{
SendInput {Volume_Mute}
}
else if GetKeyState("RAlt")
{
SendInput {Volume_Down}
}
else if GetKeyState("RCtrl")
{
SendInput {Volume_Up}
}
But this just runs & terminates. Is there a way to achieve what I'm after?
The problem with your solution is that RAlt & RCtrl::SendInput {Volume_Mute} turns RAlt into a "prefix key" and according to the Hotkeys section of Autohotkey help "The prefix key loses its native function".
Try this instead:
RAlt::Volume_Down
RCtrl::Volume_Up
#if GetKeyState("RAlt", "P")
RCtrl::Volume_Mute
#if GetKeyState("RCtrl", "P")
RAlt::Volume_Mute
I want to detect double press on AltGr.
According to documentation:
; Example #4: Detects when a key has been double-pressed (similar to double-click).
; KeyWait is used to stop the keyboard's auto-repeat feature from creating an unwanted
; double-press when you hold down the RControl key to modify another key. It does this by
; keeping the hotkey's thread running, which blocks the auto-repeats by relying upon
; #MaxThreadsPerHotkey being at its default setting of 1.
; Note: There is a more elaborate script to distinguish between single, double, and
; triple-presses at the bottom of the SetTimer page.
~RControl::
if (A_PriorHotkey <> "~RControl" or A_TimeSincePriorHotkey > 400)
{
; Too much time between presses, so this isn't a double-press.
KeyWait, RControl
return
}
MsgBox You double-pressed the right control key.
return
AltGr is actually a combination of LControl & RAlt. So, for AltGr, script should be something like this:
~LControl & RAlt::
if (A_PriorHotkey <> "~LControl & RAlt" or A_TimeSincePriorHotkey > 400)
{
click
KeyWait, LControl & RAlt
return
}
click 2
return
But when I try to load this script, AutoHotkey gives an error:
Maybe there is a way to make an alias for key combinations.
As mentioned in the comments, KeyWait can only wait on one key (not hotkey) at a time. You only need to wait for RAlt to be released, not the combination of LCtrl and RAlt.
This works:
~LControl & RAlt::
if (A_PriorHotkey <> "~LControl & RAlt" or A_TimeSincePriorHotkey > 400)
{
KeyWait, RAlt
return
}
MsgBox Double-click
return
However, in this case KeyWait is only being used (in combination with the default #MaxThreadsPerHotkey setting of 1) to prevent key-repeat from activating the hotkey. You can remove KeyWait and it will still detect double-presses; but it will also activate if you hold AltGr down until it auto-repeats.
Note that in your case, double-pressing the hotkey would click three times: once on the first press and an additional two times on the second press.
If you just want to use AltGr as a mouse button and allow double-click, all you need is <^RAlt::Click.
If you want to perform two different actions depending on whether it is a single or double click, you must delay the response to the first click until you know whether there's a second click. For example:
<^RAlt::
KeyWait RAlt
KeyWait RAlt, D T0.4
if ErrorLevel
MsgBox Single
else
MsgBox Double
return
I want an AHK script which when I press NumPad7 returns {.
Now, in my keyboard { is Ctrl + Alt + ´
But the script
`NumPad7::
Send, ^!´
return`
does nothing for some reason.
Update: It does work with regular keys like this:
p::
Send; ^!´
return
Edit 2:
NumLock had to be on, now it works fine.
This script gives you { from 7 on numeric keypad regardless of NumLock state:
NumPad7::
NumPadHome::
SendRaw {
Return
Similar to what this question covers, I'm trying to bind two sequences of keys.
Ideally I'd like to bind Alt DOWN,-,-,-,Alt UP to an em-dash (—) and Alt DOWN,-,-,Alt UP to an en-dash (–).
What I have almost works for em-dashes but not quite:
; Em-dash
!-::
Input Key, L1
if Key=-
Input Key, L1
if Key=-
Send {ASC 0151}
return
; En-dash
;!-::
;Input Key, L1
;if Key=-
;Send {ASC 0150}
;return
The em-dash sequence works like Alt+-,-,-, instead of what I'm trying to match. I'm not sure how to only test for Alt DOWN and Alt UP. The en-dash sequence fails altogether to bind because !- has already been bound.
Have a look at this one:
dashCount := 0
!-::
dashCount++
if(dashCount = 1) {
SetTimer, WaitForAlt, -1
}
return
WaitForAlt:
KeyWait, Alt
if(dashCount = 2) {
Send {ASC 0150}
} else if(dashCount = 3) {
Send {ASC 0151}
}
dashCount := 0
return
It seems to do the job well. The code works by counting each time Alt + - gets pressed. Concurrently, a pseudo-thread is spawned that waits for Alt to be released and then sends the appropriate dash, depending on the counter.