pynput - 不重置按下的按键

发布于 2025-01-15 12:23:04 字数 2464 浏览 3 评论 0原文

ShortcutBOX = [
    {keyboard.Key.ctrl_l, keyboard.Key.f1}
]
FinDoc = [
    {keyboard.Key.ctrl_l, keyboard.Key.f2}
]
LastPatient = [
    {keyboard.Key.ctrl_l, keyboard.Key.f3}
]
# The currently active modifiers
current = set()

#Popup ShortCut 
def executeMenu():
    print('['+datetime.now().strftime("%H:%M:%S")+']:',"Showing shortcuts list")
    tkinter.messagebox.showinfo("Rapid Shortcuts",  "CONTROL + F1 - Shortcut list"'\n'"CONTROL + F2 - Create Financial Document")

#Move to FinDoc
def executeFinDoc():
    print ('['+datetime.now().strftime("%H:%M:%S")+']:',"Selected Create Financial Document")
    driver.get(RapidURL+"/financial/new-sale")

#Move to latest patient visited
def executeLastPat():
    print ('['+datetime.now().strftime("%H:%M:%S")+']:',"Selected Latest Patient")
    Do.click(driver.find_element(by=By.XPATH, value="//img[@id='history-dropdown']"))
    Do.click(driver.find_element(by=By.XPATH, value="//li[@id='history_wrapper']//li[1]//div[1]//div[1]"))

#execute Shortcut INFO
def HotkeyPress(key):
    if any([key in COMBO for COMBO in ShortcutBOX]):
        current.add(key)
        if any(all(k in current for k in COMBO) for COMBO in ShortcutBOX):
            executeMenu()

#Remove keys
def HotkeyRelease(key):
    if any([key in COMBO for COMBO in ShortcutBOX]):
        current.remove(key)

#execute fin doc
def FinnyDoc(key):
    if any([key in COMBO for COMBO in FinDoc]):
        current.add(key)
        if any(all(k in current for k in COMBO) for COMBO in FinDoc):
            executeFinDoc()

#Remove keys
def FinnyRelease(key):
    if any([key in COMBO for COMBO in FinDoc]):
        current.remove(key)

#execute latest patient
def lastpatpress(key):
    if any([key in COMBO for COMBO in LastPatient]):
        current.add(key)
        if any(all(k in current for k in COMBO) for COMBO in LastPatient):
            executeLastPat()

#Remove Keys
def lastpatrelease(key):
    if any([key in COMBO for COMBO in LastPatient]):
        current.remove(key)

#Listen for keyboard presses
with keyboard.Listener(on_press=HotkeyPress, on_release=HotkeyRelease) as listener:
    with keyboard.Listener(on_press=FinnyDoc, on_release=FinnyRelease) as listener:
        with keyboard.Listener(on_press=lastpatpress, on_release=lastpatrelease) as listener:
            listener.join()    

当我尝试运行它时,在新闻上等等,它工作正常,并且它执行了它应该做的事情,但发布部分似乎不想工作,我的意思是,它不松开按键。 每当我按下 Control 时,它都会再次执行按下部分(无需单击 f2 或 f1 或 f3)

ShortcutBOX = [
    {keyboard.Key.ctrl_l, keyboard.Key.f1}
]
FinDoc = [
    {keyboard.Key.ctrl_l, keyboard.Key.f2}
]
LastPatient = [
    {keyboard.Key.ctrl_l, keyboard.Key.f3}
]
# The currently active modifiers
current = set()

#Popup ShortCut 
def executeMenu():
    print('['+datetime.now().strftime("%H:%M:%S")+']:',"Showing shortcuts list")
    tkinter.messagebox.showinfo("Rapid Shortcuts",  "CONTROL + F1 - Shortcut list"'\n'"CONTROL + F2 - Create Financial Document")

#Move to FinDoc
def executeFinDoc():
    print ('['+datetime.now().strftime("%H:%M:%S")+']:',"Selected Create Financial Document")
    driver.get(RapidURL+"/financial/new-sale")

#Move to latest patient visited
def executeLastPat():
    print ('['+datetime.now().strftime("%H:%M:%S")+']:',"Selected Latest Patient")
    Do.click(driver.find_element(by=By.XPATH, value="//img[@id='history-dropdown']"))
    Do.click(driver.find_element(by=By.XPATH, value="//li[@id='history_wrapper']//li[1]//div[1]//div[1]"))

#execute Shortcut INFO
def HotkeyPress(key):
    if any([key in COMBO for COMBO in ShortcutBOX]):
        current.add(key)
        if any(all(k in current for k in COMBO) for COMBO in ShortcutBOX):
            executeMenu()

#Remove keys
def HotkeyRelease(key):
    if any([key in COMBO for COMBO in ShortcutBOX]):
        current.remove(key)

#execute fin doc
def FinnyDoc(key):
    if any([key in COMBO for COMBO in FinDoc]):
        current.add(key)
        if any(all(k in current for k in COMBO) for COMBO in FinDoc):
            executeFinDoc()

#Remove keys
def FinnyRelease(key):
    if any([key in COMBO for COMBO in FinDoc]):
        current.remove(key)

#execute latest patient
def lastpatpress(key):
    if any([key in COMBO for COMBO in LastPatient]):
        current.add(key)
        if any(all(k in current for k in COMBO) for COMBO in LastPatient):
            executeLastPat()

#Remove Keys
def lastpatrelease(key):
    if any([key in COMBO for COMBO in LastPatient]):
        current.remove(key)

#Listen for keyboard presses
with keyboard.Listener(on_press=HotkeyPress, on_release=HotkeyRelease) as listener:
    with keyboard.Listener(on_press=FinnyDoc, on_release=FinnyRelease) as listener:
        with keyboard.Listener(on_press=lastpatpress, on_release=lastpatrelease) as listener:
            listener.join()    

When I try to run this, on press and so on it works fine and it does what it is meant to do but the on-release section doesn't seem to want to work, what I mean by that is, It doesn't release the keys.
whenever I just press control it does the on press section again (without clicking f2 or f1 or f3)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文