在 Webots 中访问键盘输入
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
我正在尝试修改控制器文件 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