keyboard control

Typically: "How do I... ", "How can I... " questions
Post Reply
Varshitha
Posts: 11
Joined: 15 Nov 2023, 05:58

keyboard control

Post by Varshitha »

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

fferri
Posts: 1230
Joined: 09 Sep 2013, 19:28

Re: keyboard control

Post by fferri »

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.:

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
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...).

Varshitha
Posts: 11
Joined: 15 Nov 2023, 05:58

Re: keyboard control

Post by Varshitha »

Thank you so much for the reply. Will try that

coppelia
Site Admin
Posts: 10375
Joined: 14 Dec 2012, 00:25

Re: keyboard control

Post by coppelia »

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

Post Reply