Shouldn't hotkeys not be sent to the active window?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
therefore
Posts: 9
Joined: 30 Nov 2022, 15:38

Shouldn't hotkeys not be sent to the active window?

Post by therefore » 30 Nov 2022, 15:47

Using ahk V2.0-beta 15 with Win 10.

Simple script to move my mouse to the center of my primary screen (from among four screens):

Code: Select all

#SingleInstance Force
!^+c:: ;Alt + Ctrl + Shift c
{

    CoordMode "Mouse", "Screen"    ; this is a must as the mouse coordinate are now relative to the whole screen

    MouseMove A_ScreenWidth // 2, A_ScreenHeight // 2, 0
    
    return
}
[Mod edit: [code][/code] tags added.]

Works great. But when I am reading a Google Docs document, Alt + Ctrl + Shift c changes it to view only (both FF and Chrome). And then moves the mouse.

I thought the hotkey would be intercepted and not sent on to the active window. When I redefine F1, it gets ignored by the active window.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Shouldn't hotkeys not be sent to the active window?

Post by swagfag » 30 Nov 2022, 17:08

check ListKeys if the hotkey is implemented using the keyboard-hook. if its not, then Chrome is likely intercepting it with its own hook before the OS processes the keypress(and invokes ur code). in that case u can try #UseHook

if it is already using it, then Chrome could be overriding ahk's hook with a hook of its own. in that case, u can try suspend/unsuspending ur hotkeys which would put ahk's hook back on top, but its a crapshoot as to how long this would work for. u might have to keep doing it periodically, if Chrome does so too

therefore
Posts: 9
Joined: 30 Nov 2022, 15:38

Re: Shouldn't hotkeys not be sent to the active window?

Post by therefore » 30 Nov 2022, 17:36

Thanks swagfag. By surrounding the hotkey with #UseHook True and then #UseHook False, it now works properly.

There was no info in ListKeys about this particular hotkey nor did Suspending/Unsuspending do the trick. Too bad there is not an obvious way to analyze which hooks are happening in the system and in what order. What I gather from you response is that ahk may or may not intercept the keystroke before another hook has stepped in first, in this case, I guess both Firefox and Chrome as they both received the Alt + Ctrl + Shift c before ahk and changed to view only as Alt + Ctrl + Shift c is the key to do so.

I wish I had a better understanding of the whens and why but I am sure a lot more studying will make it clear. :) Thanks!

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Shouldn't hotkeys not be sent to the active window?

Post by lexikos » 30 Nov 2022, 19:45

I doubt that Chrome or Firefox uses any kind of keyboard hook to implement its keyboard shortcuts.

If you hold ^+!c for a moment, you should find that Google Docs switches to view when you release the key. Registered hotkeys (handled by the OS) do not suppress the key-up event.

therefore
Posts: 9
Joined: 30 Nov 2022, 15:38

Re: Shouldn't hotkeys not be sent to the active window?

Post by therefore » 03 Dec 2022, 15:14

Thank you. After doing a lot of reading of the boards and the documentation, it is slowly making some sense to me. The moral that I'm getting is to use #UseHook and not to rely on registered keys. In another post, you indicated a desire to even make it the default.

I'm surprised that the Window's registered keys don't suppress the key-up event. Is that how AHK is implemented or simply a design flaw in Windows?

Again, thanks for the guidance (and for all of your board posts!).

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Shouldn't hotkeys not be sent to the active window?

Post by lexikos » 03 Dec 2022, 23:54

There is no way to register a hotkey with different behaviour. The documentation for RegisterHotKey doesn't guarantee any particular behaviour in the first place. It just allows you to register a key combination for the system to notify you when it is pressed.

Post Reply

Return to “Ask for Help (v2)”