![](/img/trans.png)
[英]Accessing tkinter keyboard input from controller class instead of GUI class
[英]Accessing Keyboard Input in Webots
我试图修改控制器文件 Highway_overtake.py 以访问用户的键盘输入。 按照文档操作后,出现相关代码如下:
from Controller import Keyboard
keyboard = Keyboard();
keyboard.enable(50);
....
[other webots controller logic]
while driver.step () != -1
key = keyboard.getKey( )
if(key ==Keyboard.CONTROL+ord('M')):
print 'Key Pressed'
我相信这是逐字记录文档,并尝试使用各种不同的键输入修改示例。 我应该如何进行?
我不知道您的代码有什么问题,但是,您可以通过以下方式在 webots 中从键盘获取输入:
from controller import Keyboard
timestep = int(robot.getBasicTimeStep())
keyboard=Keyboard()
keyboard.enable(timestep)
while robot.step(timestep) != -1:
key=keyboard.getKey()
if (key==Keyboard.CONTROL+ord('M')):
print ('Ctrl+M is pressed')
#here you get print only when you press ctrl and m togather
#in webots ctrl + B is a shortcut which mess the window layouts thats why i changed B to M
# hope it helps
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.