Questions about the use of sim_message_keypress

Typically: "How do I... ", "How can I... " questions
Post Reply
Lnferior
Posts: 23
Joined: 20 Jul 2022, 17:49

Questions about the use of sim_message_keypress

Post 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

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

Re: Questions about the use of sim_message_keypress

Post 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

Post Reply