pynput icon indicating copy to clipboard operation
pynput copied to clipboard

Hotkey modifier not needed (perhaps system views as pressed) after ALT+TAB

Open jb261 opened this issue 2 years ago • 0 comments

Hotkey modifier not needed (perhaps system views as pressed) after ALT+TAB

Windows 10, Python 3.9.12, pynput 1.7.6

from pynput import keyboard

def function_1():
    print('Function 1 activated')

with keyboard.GlobalHotKeys({
        '<alt>+<ctrl>+b': function_1}
        ) as h:
    h.join()

Expected behavior is that the function (a print statement) executes every time CTRL+ALT+B is pressed, but not any other key combination. I'm finding CTRL+ALT+SHIFT+B also triggers the function. I guess this makes sense if the listener code isn't excluding keys that are not in the set it is listening for.

After pressing ALT+Tab to switch windows, CTRL+B will also trigger the function. Almost as if the code sees ALT key as being held down? But I find CTRL+B does not trigger function after ALT+[some other key], but does reliably trigger function after ALT+TAB.

jb261 avatar Sep 17 '22 21:09 jb261