I am trying to control my robot using my keyboard. I have tried using sim.getSimulatorMessage() but the message always returns -1, it isn't taking my keyboard input. Is there a way to control the robot using arrow keys. Please help me figure this out.
Thanks
keyboard control
Re: keyboard control
Keyboard input is not supported by CoppeliaSim nor by the UI plugin. This is mainly motivated by the fact that with graphical user interfaces, the ability to receive keyboard events depends on which widget has the focus and other factors.
There is however one widget in simUI that can receive keyPress events (only if it has focus), so you can kind of exploit that feature, e.g.:
Better alternatives would be using UI widgets, writing your own plugin, or using a joystick with some of the plugins that can handle such devices (Joy or SDL I think...).
There is however one widget in simUI that can receive keyPress events (only if it has focus), so you can kind of exploit that feature, e.g.:
Code: Select all
function keyPress(uiHandle, id, key, text)
print('pressed', key)
end
function sysCall_init()
sim = require('sim')
simUI = require('simUI')
ui = simUI.create[[<ui layout="none" title="Keyboard input window" closeable="true">
<table geometry="0,0,200,80" on-key-press="keyPress" />
</ui>]]
end
Re: keyboard control
Thank you so much for the reply. Will try that
Re: keyboard control
Hello,
you should be able to react to key presses using sim.getSimulatorMessage. Can you check if the demo model models/examples/simple Ackermann steeing.ttm works? (Make sure the focus is on the rendering window and the simulation is running). Presse the arrows and the vehicle should move.
Cheers
you should be able to react to key presses using sim.getSimulatorMessage. Can you check if the demo model models/examples/simple Ackermann steeing.ttm works? (Make sure the focus is on the rendering window and the simulation is running). Presse the arrows and the vehicle should move.
Cheers