我想运行一个命令,直到放开钥匙
我已经在RC汽车上编码了一些电动机,并复制了使用诅咒模块的一些代码。在我控制汽车时,它运行了相同的命令,例如向前或离开,直到我给它另一个命令,例如右侧。我希望它在释放钥匙时停止移动。我该怎么做?
try:
shell = curses.initscr()
shell.nodelay(False)
curses.noecho()
while True:
key = shell.getch()
if key == 65:
right()
time.sleep(0.1)
这就是我一直使用的代码,因此对任何帮助都将不胜感激。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您描述它的方式是您正在寻找一种确定“不按密钥”的方法。
AS 真实。
之后,您可以将“ -1”案例分配给停止命令(无论您的情况如何)。
The way you describe it you are looking for a way to determine "no key pressed".
As documented, getch returns -1 in "no delay mode", i.e. setting shell.nodelay() to True.
Afterwards, you can assign the "-1" case to a stopping command (whatever that is in your case).