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
Related
I'm trying to use Auto Hot Key to replace $ with %. I also am replacing & with $.
My problem is that when I press the & key (now remapped to $), it thinks I'm actually pressing $, so it triggers the code and types %.
This is the code:
~::#
#::?
%::^
^::~
$::Sendraw `%
&::$
?::+
/::_
+::&
=::/
_::=
My keyboard layout doesn't have these keys as actual keys, so I can't really test this for you, but I can still tell you what will likely fix the problem, and then an other version which will definitely fix the problem.
So the thing that will likely fix the problem is using the $ modifier (docs). You should only need it for the $::Sendraw `% hotkey, because the other hotkeys use the remapping syntax and will automatically do what adding the $ does.
So your script would look like this:
~::#
#::?
%::^
^::~
$$::SendInput, `%
&::$
?::+
/::_
+::&
=::/
_::=
(and I also switched to using SendInput because SendRaw really made no sense there)
That should work if all the hotkeys are as actual keys on your keyboard layout (as opposed to being accessible with modifier key combos (e.g. CTRL + ALT + 2), like they are on my keyboard layout).
Why it wouldn't work when having to mess with modifiers keys is a bit more complicated. I can explain it in detail if you're actually interested, but for now I'll just say it's because of the blind send mode the remapping syntax uses.
So, not using the remapping syntax like this should ensure it'll work on any keyboard layout no matter what:
*~::SendInput, #
*#::SendInput, ?
*%::SendInput, {^}
*^::SendInput, ~
*$::SendInput, `%
*&::SendInput, $
*?::SendInput, {+}
*/::SendInput, _
*+::SendInput, &
*=::SendInput, /
*_::SendInput, =
Here we're using the * (docs) modifier to deal with having to hold modifier keys to access hotkeys. And we're not using $ modifier, because using * already does what $ does. So having them both would be redundant.
+4::SendInput, `%
This should work fine.
I have used Linux and KDE for a long time and my muscle memory wants to switch keyboard layouts by pressing both shift keys simultaneously. Can I use AutoHotKey to implement that on Windows?
I lack two pieces of information:
How do I remap "both shift keys pressed at the same time"? I can use + to capture the pressing of one shift key, but how about both?
How can I send the key combination that Windows uses to switch layouts (Ctrl+Shift in my current setup)? More generally, how can I remap something to a key combination?
Use combo key notation and L/R prefix, see the documentation (or the help file):
LShift & RShift::send {LShift down}{LCtrl down}{LShift up}{LCtrl up}
I wanted to disable native Windows hotkey altogether. The following works well so far, including console windows.
~RShift & ~LShift::
~LShift & ~RShift::
INPUTLANGCHANGE_FORWARD := 0x2
WM_INPUTLANGCHANGEREQUEST := 0x0050
WinGet, windows, List
Loop % windows {
PostMessage WM_INPUTLANGCHANGEREQUEST, INPUTLANGCHANGE_FORWARD, % Lan, , % "ahk_id " windows%A_Index%
}
return
I am not asking to remap Caps Lock to other modifier keys but I want to configure Caps Lock as one of modifier key for my own usage. Any ideas? :D
On Windows you can use AutoHotKey(usually briefly as ahk) with the WinActive function to make the ahk script only work when you're in vscode, mapping CapsLock+* keys to usually-not-used combinations like ctrl+shift+alt+* and write the ctrl+shift+alt+* keys to vscode's key configs.
It would roughly look like this:
; comment: the class used here is made up
; right click a running script in the system tray and go to "window spy" to get the right class name
; there are also usual `if`s but this one applies the condition to all the code following it
#If WinActive("ahk_class VSCode")
CapsLock & a::
SendInput, ^+!a
return
And of course if you want to get the function of capslock in the editor, you can easily use a combination like CapsLock & Shift to acomplish it like above.
For x11 OSes like most Linux distros, use xmodmap. Something like
keycode 66 = Alt_L Meta_L
clear mod1
add mod1 = Alt_L Meta_L
in your .Xmodmap file should suffice.
Then run:
xmodmap .Xmodmap
I have the follow autohotkey map:
^j:: Send ^{PgUp}
This works fine. It maps control + j to control+pagedown.
But I would like to map the keycombination
s & j:: Send ^{PgUp}
So when you press s and j simultaneously, it will send control pagedown to Windows.
Then i'm running into the problem that the character 's' never shows up in my input field, but the character 'j' is appearing as normal. That is weird. The combo key is working, by the way. But I want to get the character 's' key working too.
And are there ways to map the key combination sj (when the both are pressed simultaneously) ?
~s & j::
Send ^{PgUp}
return
was the winning answer by the way, got it from the user RCHP on Autohotkey forum :)
This is by design. The first key of a custom hotkey always loses it's original function. To work around this, create a new hotkey for "s" that sends "s".
In AutoHotKey, hotkeys override their normal function, which is generally desirable. In order to avoid this behavior, prefix your hotkey with a tilde.
~s & j:: Send ^{PgUp} return
The terrific AHK docs explain this.
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