python - 在 Webbots 中访问键盘输入
问题描述
我正在尝试修改控制器文件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'
我相信这是逐字遵循文档,并尝试使用各种不同的键输入修改示例。我应该如何进行?
解决方案
我不知道您的代码有什么问题,但是,您可以通过以下方式在 webbots 中从键盘获取输入:
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
推荐阅读
- swift - swift-lldb 编译失败,出现 c++11 错误
- angular - 使用角度创建动态内容
- security - 沙发认证。新的反应原生项目
- javascript - 如何处理导致未解决的承诺的异常
- android - 用于对象数组的 Android Moshi JsonAdapter
- sdn - Mininet 由于 ovs-appctl 安装失败:无法连接到“/var/run/openvswitch/ovsdb-server.4301.ctl”(没有这样的文件或目录)
- makefile - 如何在makefile中搜索头文件并创建丢失的目录
- flutter - Flutter - 来自另一个屏幕的子选项卡导航
- jquery - 在 kendo ui 中创建或编辑后返回警报
- matlab - 如何在图形 Matlab App Designer 上获得下拉菜单