Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding some global hotkeys fails on Windows 10

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?

like image 741
Ram Rachum Avatar asked Oct 20 '19 09:10

Ram Rachum


1 Answers

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.

like image 109
Lexikos Avatar answered Sep 21 '22 17:09

Lexikos