在Python中的任何按键上停止keyboard.record()函数 [英] Stop keyboard.record() function at any keypress in Python

查看:106
本文介绍了在Python中的任何按键上停止keyboard.record()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Python中找到了这个 keyboard 模块,该模块用于使用 keyboard.record()记录键盘事件(主要是从我得到的信息),该模块接收一个字符串作为参数,指示该功能应在哪个按键上停止.

I found this keyboard module in Python which is used to log keyboard events (from what I got, mainly) using keyboard.record(), which takes in a string as a parameter, indicating at which keypress the function should stop.

所以我的问题是..有什么办法可以使该功能在任何按键下停止?据我所知,该模块没有特殊的关键字来表明这种情况.

So my question is.. is there any way to make the function stop at any keypress? As far as I know the module has no special keyword which would indicate such a thing.

就像我尝试做的那样

keys_pressed = keyboard.record(until ='any')

但这会导致错误.

推荐答案

如果您只需要在第一次按键时停止(并记录),我看不到使用keyboard.record()的意义.

I don't see the point to using keyboard.record() if all you need it for is to stop at (and record) only the first keypress.

相反,您可以像这样使用keyboard.read_key():

Instead, you could use keyboard.read_key() like this:

import keyboard
k = keyboard.read_key()  # in my python interpreter, this captures "enter up"
k = keyboard.read_key()  # so repeat the line if in the python interpreter

这篇关于在Python中的任何按键上停止keyboard.record()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆