![](/img/trans.png)
[英]How to run a piece of code when an element is present in selenium python?
[英]How to get a piece of code to run when a specific key is pressed? (python)
因此,我试图实现的是按下空格键时该功能将运行,当前我必须让用户输入一个问题的“是”或“否”。 我想减少到一个指定的击键。
如何在python中完成?
是否有多种方法可以做到这一点?
编辑:我已经看到了如何为Enter和(其他任何方式)执行此操作,但是我无法具体指定键
doing = True
while doing:
do_again = input('ready to do? Enter = to do. Q = quit')
if do_again.lower() != 'q':
# do thing #
else:
doing = False
编辑2:我已经下载了键盘,并且已经在目录中浏览了很长时间,并且玩了很多我希望可以使用的功能,但是我仍然没有运气。 这是我最近的一些尝试
最近尝试1
while True:
roll = keyboard.is_pressed('57')
if roll is True:
print('you rolled a', randint(0, sides))
input('would you like to roll again?\r\n')
continue
最近尝试2
while True:
roll = keyboard.send('57', do_release=True)
if roll is True:
print('you rolled a', randint(0, sides))
input('would you like to roll again?\r\n')
continue
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.