[英]How to find the multiple key presses in python(like ctrl+c or ctrl+v)
How to find the multiple key presses in python(like ctrl+c or ctrl+v).如何在 python 中找到多个按键(如 ctrl+c 或 ctrl+v)。 I am using pynput https://pypi.org/project/pynput/ to monitor my keyboard pressing keys.
我正在使用 pynput https://pypi.org/project/pynput/来监控我的键盘按键。 I want to be able to print the key shortcuts as it is (Ctrl+c) rather than hex value which is what you get when you press multiple keys at the same time.
我希望能够按原样 (Ctrl+c) 打印快捷键,而不是同时按下多个键时得到的十六进制值。 When I hold a key and press another key I want to print like "first key + second key" How can i achieve this (if possible cross platform and using pynput and be able press using keyboard.send(key combination)) my current code is
当我按住一个键并按下另一个键时,我想像“第一个键 + 第二个键”一样打印我如何实现这一点(如果可能的话,跨平台并使用 pynput 并能够使用keyboard.send(组合键)按下)我当前的代码是
from pynput.keyboard import Listener
def on_press(key):
print(key)
with Listener(on_press=on_press) as listener:
listener.join()
My os is windows 7 python 3.8.8 Thanks我的操作系统是 windows 7 python 3.8.8 谢谢
I've found this on我发现这个
https://code-maven.com/catch-control-c-in-python
https://code-maven.com/catch-control-c-in-python
import signal
import time
import readchar
def handler(signum, frame):
msg = "Ctrl-c was pressed. Do you really want to exit? y/n "
print(msg, end="", flush=True)
res = readchar.readchar()
if res == 'y':
print("")
exit(1)
else:
print("", end="\r", flush=True)
print(" " * len(msg), end="", flush=True) # clear the printed line
print(" ", end="\r", flush=True)
signal.signal(signal.SIGINT, handler)
count = 0
while True:
print(f"{count}", end="\r", flush=True)
count += 1
time.sleep(0.1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.