pynput - 不重置按下的按键
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论