简体   繁体   English

如何在python中找到多个按键(如ctrl+c或ctrl+v)

[英]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.

相关问题 如何使用 ctrl+c 和 ctrl+v 将文件夹从一个文件夹复制、剪切到另一个文件夹 - How to copy, cut folder from one folder to another using ctrl+c and ctrl+v 每当用户连续按ctrl + c时如何循环遍历键盘中断 - How do I loop through keyboard interrupt whenever the user presses ctrl+c multiple times in a row 如何在python中从url复制所有文本(例如,使用Webbrowser的[Ctrl + A] [Ctrl + C])? - How to copy all the text from url (like [Ctrl+A][Ctrl+C] with webbrowser) in python? 对 Pandas DataFrame 中的元素进行简单的剪切粘贴操作(就像我们使用鼠标或 CTRL+C 和 CTRL+V 对 Excel 的单元格所做的那样) - A simple Cut Paste operation for an element in Pandas DataFrame (as we do for an Excel's cell using a mouse or CTRL+C & CTRL+V) python3:如何使用pynput按Ctrl+X(剪切)和Ctrl+V? - python3: how to use the press Ctrl+X (cut) and Ctrl+V using pynput? Python-如何在Ctrl + C上插入主脚本 - Python - How to interupt the main script on Ctrl+C 在python中按下CTRL + C时如何优雅地终止循环 - How to terminate loop gracefully when CTRL+C was pressed in python 在CTRL + C之后如何关闭在线程中运行的Python套接字? - How to close Python socket running in a thread after CTRL+C? 如何在 cmd/python 中使用 Ctrl+C 禁用中断 - How to disable interruption with Ctrl+C in cmd/python 如何使用 Python cmd shell 捕获 ctrl+c - How to catch ctrl+c with Python cmd shell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM