1 year ago

#312733

test-img

PhillyBoi

pynput - not resetting pressed keys

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)

python

pynput

0 Answers

Your Answer

Accepted video resources