Page 1 of 1

Questions about the use of sim_message_keypress

Posted: 20 Apr 2024, 05:52
by Lnferior
I've seen online documentation of people using sim_message_keypress to get input from the keyboard, but I haven't found a description of how to use it or what to include in the Coppeliasim user manual. Can you tell me how this statement is used and where in the manual I should look for the relevant content.
Cheers

Re: Questions about the use of sim_message_keypress

Posted: 24 Apr 2024, 07:01
by coppelia
Hello,

this is an undocumented feature. Use following to get inspiration:

Code: Select all

--lua

sim = require'sim'

function sysCall_thread()
    while true do
        -- Read the keyboard messages (make sure the focus is on the main window, scene view):
        local msg, auxData = sim.getSimulatorMessage()
        if msg ~= -1 then
            if msg == sim.message_keypress then
                print("The pressed key corresponds to code " .. tostring(auxData[1]))
            end
        end
    end
end
Cheers