I want to use the 4 buttons above the numpad for data entry, with the "calc" button as a sort of modifier, so I can do multiple things with them. I'm having trouble making key combos work.
Here are a few different versions of the code I've tried, to get a way to type the "(" character, but none of these work.
Launch_App2 & Volume_Down:: ( ;- fails
Launch_App2 & Volume_Down::SendInput, ( ;- fails
vkB7 & vkAE::SendInput, ( ;- fails
SC121 & SC12E::SendInput, ( ;- fails
Here's some more information about the individual keys.
; row above numpad, from left to right
; VK SC Type Key
; ----------------------------------
; AD 120 a Volume_Mute
; AE 12E a Volume_Down
; AF 130 a Volume_Up
; B7 121 a Launch_App2
What I can do however is to remap any one of those keys individually, for example with Volume_Mute:: Esc but I don't seem able to combine them using &. How can I use the keys in combination? I'm using the latest versions of AutoHotKey and Windows 10.
There is certainly a problem with media keys on USB keyboards that doesn't happen on ps2 ports, and it involves the keyboard hook (which undoubtedly you are using with other hotkeys). https://autohotkey.com/board/topic/85889-issues-with-keywait-media-play-pause/
Maybe try something like this to get the quasi-combination you want:
SC121:: ; 121 is Logitech Calc key (use your key's value).
KeyWait, sc110, D L ; 110 is the Logitech media-back key
MsgBox, %A_ThisHotkey% was pressed. ; SC121
return
So now, if you press the Calc button, nothing happens until you release it and then press the media-back key. That's when you will see the message box. You can also press and hold the Calc key, then press and hold the media-back key and release the Calc key to get the MsgBox.
Hth,
Related
Background: I'm trying to have a f-mode and d-mode which means if I press down the f key and press another key like i then nothing happens excepts a shortcut. let say it will send Up key instead of f and I.
Issue: how I can remap a pressed key (I in my example) to a shortcut (Up as example)?
Code:
d::
f::{
;...
loop{
if !GetKeyState("f","p") && !GetKeyState("d","p"){
break
}
if GetKeyState("i","p") {
OutputDebug "i"
send "{up}"
continue
}
; ...
}
}
Looks like you want to make a custom combination.
From the Docs:
You can define a custom combination of two keys (except joystick
buttons) by using " & " between them. In the below example, you would
hold down Numpad0 then press the second key to trigger the hotkey:
Numpad0 & Numpad1::MsgBox You pressed Numpad1 while holding down Numpad0.
Numpad0 & Numpad2::Run Notepad
But also note:
The prefix key loses its native function: In the above example,
Numpad0 becomes a prefix key; but this also causes Numpad0 to lose its
original/native function when it is pressed by itself. To avoid this,
a script may configure Numpad0 to perform a new action such as one of
the following:
Numpad0::WinMaximize A ; Maximize the active/foreground window.
Numpad0::Send {Numpad0} ; Make the release of Numpad0 produce a Numpad0 keystroke. See comment below.
This is to prevent holding down a key from spamming inputs while you wait to press the second part of a key combination. So essentially, your 'f' and 'd' keys will now perform their normal functions when you release them instead of initially pressing them down.
Anyways, the code would become:
f & i::
d & i::
Send {Up}
return
f::f
d::d
I want to create a hotkey using a backslash key (\). Namely, I would like to assign Media_Prev to Windows button + backslash. I have tried both LWin & \::Media_Prev and #\::Media_Prev. However, these do not work: it just normally sends the backslash character. In AutoHotkey's key history, I do see that both \ and LWin register when I press this key combination.
Interestingly, something like LWin & c::Media_Prev or #v::Media_Prev does work well, just not with the backslash character.
This worked for me, using AHK version 1.1.13.01
LWin & \:: run Notepad
you can also use scan codes - something like
SC15B & SC02B:: run Notepad
should have the same effect
reference: here
I successfully tested the following:
<#vk dc::Send {Media_Prev}
< is Left key
# is Windows key
VK DC is virtual key number DC (you can find this code using AHK menu View > Key History and Script Info). With VK, the same key works regardless of active keyboard layout.
Note: Don't do LWin & key or Ctrl & key etc... & has a bit different meaning. For the above purpose AHK provides prefixes as shown above, e.g. ^b or #F1 etc. See AHK help on Remapping Keys and Buttons
Key Spam does not work so good.
Here is the code:
Loop
{
If GetKeyState("z", "P")
send w
If GetKeyState("g", "P")
send a
If GetKeyState("j", "P")
send d
If GetKeyState("h", "P")
send s
}
but when I hold z or zg together, then the original keys z and zg come all time once or twice between the w or wa output.
What can I write that the keys z+g+h+j never will be seen in the text file only w+a+s+d if I run this script?
Karoline, you are going about it the wrong way. Autohotkey was designed to do just what you really want to do.
As MCL says in his comment, you need only to map your keys to a send function
Put this in your script:
z::send w
g::send a
j::send d
h::send s
Now, when you push z it will type w instead.
Keep in mind that this is global over your entire computer unless you limit it to notepad using IfWinActive. The script will not exit on its own.
but this doenst work like i want
i want that i can press g+z same time or z+j same time or g+h same time or h+j same time
and that i get then awawawawaw or asasasasasasas or wdwdwdwdwdwdwd
that when i press 2 buttons same time it switch output ever 1 char
and when i use your answer and holz z it spams wwwwwwwwwwwwwwwwwwwwwwwwwwwww
and if if press then z+g it only continou spaming wwwwwwwwwwwwww not wawawawawawawawaw
thans
Karoline
According to your "answer", you are targeting a keyboard behaviour that's not standard. That is, using remapped keys with AHK or not, when pressing two letter keys simultaneously, solely the key pressed at last will continue firing.
Here's an example on how you can achieve an alternating behaviour instead:
SendMode, Input
g & z::
z & g::
Send, aw
return
g::Send, a
+g::Send, A
z::Send, w
+z::Send, W
You will have to explicitely define every custom combination with an & modifier, which makes them prefix keys. This comes with an upside and with a small downside: The upside is, you can now keep pressing your combination and it will continue firing two keys in an alternating fashion; no loop or the like required. The downside: You need to reconstruct prefix hotkeys' original behaviour. In our example, that's sending a lowercase or uppercase letter.
I work with a hospital data entry system where no customization is allowed. I have found AutoHotKey to provide effective ways to work around the this system's "slow clunkiness".
What I need are more function keys on the keyboard. The best way I have found to approximate that is by remapping key pairs 1 Q:: Alt n, 2 w::ctrl r....ect. The best I could come up with was from AHK site's example and explanation of how to remap letter keys to other letter key destination. I tweaked and adjusted and came up with the following:
1 & q::
SetKeyDelay -1, 40 ;
Send {ctrl Down} ;
Send {Blind}{f Downtemp}
return
1 & q up::
SetKeyDelay -1 ;
Send {Blind}{ctrl up}
Send {Blind}{f Up}
return
This code will do the job but it has a downside. The first key in the sequence looses it's regular function. In this case, I've lost the use of my top row of numbers to become function keys. Is it possible to have the first key revert back to it's native function automatically after it was used in the key pair? I and the other pharmacy personnel will be most grateful for any help you can provide. Thank You.
Key combinations with & produce prefix keys. To restore a prefix key's original function, you need to define it explicitely:
1 & q::Msgbox, 1
1::Send, 1
+1::Send, {!} ; SHIFT + 1 may depend on your keyboard layout
However, it makes sense to arrange your key combinations in a way that produces as few prefix keys as possible. In your example, if you want to define hotkeys like 1 + q, 2 + q, 3 + q, and so on, it may be smarter to use q as the first key, leaving you with the necessity of redefining only one key:
SendMode, Input
q & 1::Msgbox, 1
q & 2::Msgbox, 2
q & 3::Msgbox, 3
q::Send, q
+q::Send, Q
; AltGr+q and CTRL+ALT+q also do something in Germany ;)
<^>!q::Send, #
^!q::Send, #
As you can see in the example, you always have to look out for keys that have a (usually third) functionality that's triggered by AltGr or CTRL+ALT. But this strongly depends on your keyboard layout.
I'm trying to add custom keyboard commands to an application using Autohotkey.
In many of these hotkeys I would like to use the alt key in combination with some other key of my choice (any of the standard letters).
All works fine as long as I don't restrict their usage in such a manner that they work in the target application only (via the #IfWinActive directive ). If I do so, the hotkeys themselves still work, however their behavior is very strange.
I found that they get activated either if
a) I hold down the alt key and then press the second key (in my case the 'b' key) twice
or
b) I use this hotkey two times consecutively with a very short delay between the two triggerings
- The above two cases might actually be 1 case. I'm not sure...
I have no problems when doing the same with Shift or CTRL.
The 'b' key is not what's causing the problem - no alt + 'letter' combination works.
I have tried all SendModes, but so far with no effect.
Code sample:
#IfWinActive, MyAppTitle ahk_class MyAppClass
!b::
click 367, 86
return
Alt+letter commands in AutoHotkey such as !b work without issue. It's possible the version at the time of this post contained certain bugs or was out of date from the current version.
For your code, it could be done like so:
!b::
WinGetTitle, Title, A
if (RegExMatch(Title, "MyAppTitle"))
{
MouseClick, left, 367, 86
}
return