我如何使用诅咒来响应密钥按下,而无需暂停程序等待输入?
我想做的一个示例是:
import curses
while True:
key = stdscr.getch()
if key == 119:
print("key w pressed")
else:
print("w key not pressed")
不仅在输入钥匙并且Getch不返回119时,ELSE语句不断打印的位置。换句话说,我不希望Getch函数等待按键按下,我只希望它仅返回键如果正在按下键,否则请勿返回或类似的东西。
An example of what I would like to do is the following:
import curses
while True:
key = stdscr.getch()
if key == 119:
print("key w pressed")
else:
print("w key not pressed")
Where the else statement prints constantly, not only when a key is entered and getch does not return 119. In other words, I don't want the getch function to wait for a key press, I only want it to only return a key if a key is being pressed, otherwise return None or something like that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在Curses中,窗口具有
nodelay
flag。如果将其设置为true,则GETCH函数将不会等待用户输入,但是如果不读取输入,将返回-1
。In curses the window has a
nodelay
flag. If it is set to true, the getch function won't wait for user input, but will return-1
if no input is to be read.