Binding some global hotkeys fails on Windows 10
Asked Answered
H

1

9

I'm a longtime Windows user who really likes to customize his Windows with lots of different utilities (some written by myself in Python) and AutoHotKey scripts. These all use global hotkeys for their functionality.

I was recently forced to upgrade to Windows 10. One of the problems has been that some hotkeys seem to be impossible to bind to. A couple of examples are CTRL-J and CTRL-V.

I was told that I needed to mark these apps to run as administrator via Properties, but even then they don't bind successfully to these hotkeys.

Any idea how I could bind to these hotkeys?

Update:

Looks like AHK is able to bind to these keys, but the ever-useful Ditto isn't, and my wxPython programs aren't either. Any idea why the last 2 aren't able to bind to these keys, and how I can fix that?

Highsmith answered 20/10, 2019 at 9:27 Comment(11)
Both ^j::MsgBox and ^v::MsgBox work fine for me. This is a default installation with nothing special done; that is, without having modified the properties. Some Windows hotkeys are set in the registry (such as # + L), but I don't believe the two you mentioned are.Diarthrosis
@EJE You're right, I updated my question.Highsmith
You said "I was told that I needed to mark these apps to run as administrator via Properties" while it is probably the other way around: you need the AutoHotkey script to run as Administrator. See autohotkey.com/docs/Variables.htm#IsAdmin and code you can add to the start of your AutoHotkey script here autohotkey.com/docs/commands/Run.htm#RunAsAsternal
@Asternal I don't understand, if AHK seems to be the only thing that actually manages to bind to these forbidden keys, unlike Ditto and wxPython, then why is it the only one that you suggest tweaking?Highsmith
Do you see any bindings at shorcut explorer? rjlsoftware.com/software/utility/shortcutkeys/download.shtmlSac
@Sac I tried shortcut explorer now, it said "There were no shortcut keys found in any of your Windows shortcuts." and then showed an empty list.Highsmith
@RamRachum even when AHK binded those keys? That is weird. That probably means that the Win10 update broke the "traditional" way to map those. From which win10 version did you update to? My guess is that AHK is using some kind of low level way, the other are using "std." Ms way.Sac
@Sac I upgraded from Windows 7 Ultimate to Windows 10.Highsmith
ah, that explains a lot. Could you try it on fresh Windows 10 install if it behaves the same way?Sac
I don't have a fresh Windows 10 install... That's a work computer.Highsmith
I see well, you can try it at virtual machine. I have bad experience with the upgreades, something goes wrong every time.Sac
S
1

AutoHotkey implements keyboard hotkeys basically one of two ways:

  1. The system function RegisterHotkey. This only supports basic combinations of standard modifier keys and one key identified by VK. It does not support conditional hotkeys (#If). If the hotkey has already been registered by the system or another application, it fails.
  2. If RegisterHotkey couldn't be used for some reason or it failed to register the hotkey, a keyboard hook is used. This is the means by which it overrides system hotkeys and global hotkeys of other applications.

Normally, ^j and ^v are not registered as global hotkeys. Most Ctrl+ combinations are used within applications, so are not good choices for global hotkeys. ^v in particular would be a bad choice because it's often the "paste" hotkey (but not global).

When I use ^j:: or ^v:: in an AutoHotkey script on Windows 10.0.19041, ListHotkeys shows that they use the reg (RegisterHotkey) method. In that case, other programs should have no problem registering the hotkeys with RegisterHotkey as long as they are the first to do it. AutoHotkey does not do anything special to make RegisterHotkey work; it just calls the function, and awaits the WM_HOTKEY message.

However, if ListHotkeys was to show that ^j and ^v were using the k-hook method (in the absence of #UseHook or #If), that would mean something else has already registered those hotkeys. In that case, the only way to make RegisterHotkey work is to find whatever registered them (using general troubleshooting techniques like performing a clean boot), and get rid of it (or change its hotkeys if you can). For example, if you terminate explorer.exe, it is possible to register standard hotkeys like #e with RegisterHotkey.

Alternatively, if your program implements a low level keyboard hook (the same as AutoHotkey's), it can detect the hotkey by watching for Ctrl and J or V keydown and keyup events.

The program implementing the hotkey does not need to run as administrator. However, if the active/focused window belongs to a program which is running as administrator, only other programs which run as administrator or with UI access can intercept its keyboard input.

Swinish answered 27/2, 2021 at 23:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.