Why do my Autohotkey Hotkeys not work with the Windows Hotkeys?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
BeyondDNA2021
Posts: 6
Joined: 31 May 2021, 16:20

Why do my Autohotkey Hotkeys not work with the Windows Hotkeys?

Post by BeyondDNA2021 » 30 Jul 2021, 08:34

If I create a shortcut using a single line, then the shortcut works. For example:

Code: Select all

d::right
Using this single line remap will cause the Windows hotkey Win+D to activate the same hotkey as Win+Right, which moves windows to the right, causing snapping behavior.

However, I want to make a shortcut that starts out deactivated, so I have to use a Hotkey command, which requires me to make the shortcut with multiple lines:

Code: Select all

d::
SendInput {Right}
return
When I use the Windows shortcut with this version, Win+D will still behave the same as Win+D, which views the desktop.

When I view the hotkeys using ListHotkeys, the multiple line version uses "reg", and the single line version uses "k-hook". I think this is the problem (but I don't know), so I tried using #UseHook, but that didn't seem to fix it.

So basically, I want a way to either fix multiple line hotkeys to trigger Windows hotkeys correctly, or I want to make a single line hotkey that will start disabled and can be toggled with another hotkey (which will then work correctly with Windows hotkeys).
gregster
Posts: 8999
Joined: 30 Sep 2013, 06:48

Re: Why do my Autohotkey Hotkeys not work with the Windows Hotkeys?

Post by gregster » 30 Jul 2021, 08:45

I want to make a shortcut that starts out deactivated, so I have to use a Hotkey command, which requires me to make the shortcut with multiple lines:
Why? How do you do it?
For example, directives also affect remappings.
User avatar
BeyondDNA2021
Posts: 6
Joined: 31 May 2021, 16:20

Re: Why do my Autohotkey Hotkeys not work with the Windows Hotkeys?

Post by BeyondDNA2021 » 30 Jul 2021, 09:10

Why?
I want to be able to change my wasd keys to arrow keys with the use of a hotkey, all within one script. If I can't find a way to do this, I will have to use multiple scripts and simply suspend the script that maps the wasd keys.
How do you do it?
I am using the Hotkey command which "creates, modifies, enables, or disables a hotkey while the script is running". However, it doesn't seem to work if the hotkey is created using a single line such as w::up.

Edit:

Here is the full code:

Code: Select all

Hotkey, w, off
Hotkey, s, off
Hotkey, a, off
Hotkey, d, off

w::
SendInput {Up}
return

s::
SendInput {Down}
return

a::
SendInput {Left}
return

d::
SendInput {Right}
return

#w::
Hotkey, w, toggle
Hotkey, s, toggle
Hotkey, a, toggle
Hotkey, d, toggle
return
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Why do my Autohotkey Hotkeys not work with the Windows Hotkeys?

Post by lexikos » 01 Aug 2021, 04:17

However, I want to make a shortcut that starts out deactivated, so I have to use a Hotkey command,
There are other ways, but I would recommend the Hotkey command in this case.
which requires me to make the shortcut with multiple lines:
That's simply not true.

w::up is not a hotkey. If you use ListHotkeys, you will see two hotkeys: *w and *w up. See Remapping Keys; in particular, the actual translation.

To disable or enable a remapping with the Hotkey command, you must call it once for each of the two constituent hotkeys (again, for w::up that's *w and *w up).

These two codes are exactly equivalent (aside from line numbering):

Code: Select all

d::
SendInput {Right}
return

Code: Select all

d::SendInput {Right}
What sets it apart from d::Right is the command SendInput, instead of merely a key name.

This does not allow Win+D to act like Win+Right for two reasons:
  • d:: does not include the wildcard modifier (*), so it will activate only if you are not holding any modifier keys, such as LWin/RWin.
  • SendInput {Right} is an instruction to send an unmodified Right keypress; if any modifier keys were held down, it would automatically release them for the duration of the send. The solution is to use {Blind} as shown in the remapping documentation linked above.
Another difference from the remapping is that SendInput {Right} will press and immediately release Right, without waiting for d to be released.
Post Reply

Return to “Ask for Help (v1)”