moses-palmer / pynput

Sends virtual input commands
GNU Lesser General Public License v3.0
1.77k stars 245 forks source link

Global hotkeys with F1 and F12 don't work on MacOS #503

Closed jiayouzl closed 2 months ago

jiayouzl commented 1 year ago
keyboard.HotKey.parse('<ctrl>+<alt>'),#yes
keyboard.HotKey.parse('<ctrl>+c'),#yes

macos The above 2 lines of code are normal

keyboard.HotKey.parse('<ctrl>+<f1>'),#no
keyboard.HotKey.parse('<f2>'),#no
keyboard.HotKey.parse('<f3>'),#no
keyboard.HotKey.parse('<f4>'),#no
keyboard.HotKey.parse('<f11>'),#no

macos The above 5 lines of code cannot be used normally.

# -*- coding: UTF-8 -*-

from pynput import keyboard

def on_activate():
    print('Global hotkey activated!')

def for_canonical(f):
    return lambda k: f(l.canonical(k))

hotkey = keyboard.HotKey(
    # keyboard.HotKey.parse('<ctrl>+<alt>'),#Normal
    # keyboard.HotKey.parse('<ctrl>+c'),#Normal
    keyboard.HotKey.parse('<ctrl>+<f1>'),#Invalid, abnormal
    # keyboard.HotKey.parse('<f2>'),#Invalid, abnormal
    # keyboard.HotKey.parse('<f3>'),#Invalid, abnormal
    # keyboard.HotKey.parse('<f4>'),#Invalid, abnormal
    # keyboard.HotKey.parse('<f11>'),#Invalid, abnormal
    on_activate)
with keyboard.Listener(
        on_press=for_canonical(hotkey.press),
        on_release=for_canonical(hotkey.release)) as l:
    l.join()
image
jiayouzl commented 1 year ago
from pynput import keyboard

def on_activate_f1():
    print('<f1> pressed')

with keyboard.GlobalHotKeys({
        '<f1>': on_activate_f1
}) as h:
    h.join()

This writing is also invalid.

jiayouzl commented 1 year ago

2022-10-05

I just found the above code invalid in Windows10 21H2. Can't operate normally.

Everything is normal except the f1-f12 key.

moses-palmer commented 1 year ago

Thank you for your report.

There has been a regression in the parsing and handling of hotkeys, a fix for which I just pushed. Do you have the possibility to test pynput from the master branch and see if any of your issues is resolved?

jiayouzl commented 1 year ago
pip install git+https://github.com/moses-palmer/pynput.git

Is this how it is installed?

jiayouzl commented 1 year ago

Use pip install git+https://github.com/moses-palmer/pynput.git Problem solved

moses-palmer commented 1 year ago

Thank you for your response. I will close this issue as soon as a new version is released.

hiroi-sora commented 1 year ago

I had the same problem in Windows10. HotKey <F1> don't work.

Master branch updated on 2 Jan, seems no fix included?

jiayouzl commented 1 year ago

Thank you for your response. I will close this issue as soon as a new version is released.

When will the new version be released? Now it can only be installed through GitHub, and distribution is very inconvenient.

jiayouzl commented 1 year ago

hello?

jiayouzl commented 11 months ago

When will the new version be released? Now it can only be installed through GitHub, and distribution is very inconvenient.~

moses-palmer commented 2 months ago

@jiayouzl, thank you for closing the issue, and I apologise for not reaching out earlier; I do get quite a lot of email from github, so I missed your messages.

I assume that you closed it because the new released version fixed the issue?