keyboard input

Typically: "How do I... ", "How can I... " questions
Post Reply
qiwang
Posts: 17
Joined: 25 Feb 2013, 13:34

keyboard input

Post by qiwang » 26 May 2014, 06:08

Hello,

I am trying to detect the keyboard input with "sim_message_keypress", but I couldn't find the discription of "auxiliaryData[]" for the keys. Which value should I test, if I want, for example, detect space key.

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

Re: keyboard input

Post by coppelia » 26 May 2014, 23:05

Hello,

to detect the space key, you would write something like:

Code: Select all

	message,auxiliaryData=simGetSimulatorMessage()
	while message~=-1 do
		if (message==sim_message_keypress) then
			print(auxiliaryData[1],auxiliaryData[2],auxiliaryData[3],auxiliaryData[4])
			if (auxiliaryData[1]==string.byte(' ')) then
				-- space key was pressed
			end
		end
		message,auxiliaryData=simGetSimulatorMessage()
	end
Have also a look at the child script attached to model Models/examples/simple Ackermann steering.ttm

Cheers

atoz
Posts: 57
Joined: 18 Oct 2013, 09:02

Re: keyboard input

Post by atoz » 28 May 2014, 20:13

Hi,

Is there a way to detect if a key is held down rather than pressed? If not, how would I go about implementing it? I'm trying to move a robot ONLY when a key is held.

* EDIT * Ignore this. Using a child script means that the key has to be held.

Thanks

qiwang
Posts: 17
Joined: 25 Feb 2013, 13:34

Re: keyboard input

Post by qiwang » 29 May 2014, 06:07

Hi,

I think as long as you hold the key, the child script would repeatedly receive the same pressed key with auxiliaryData[1] in each step. You can keep detecting the state of auxiliaryData[1]in your script, and let the robot stop, when the state of auxiliaryData[1] changed. I hope this works for you.
atoz wrote:Hi,

Is there a way to detect if a key is held down rather than pressed? If not, how would I go about implementing it? I'm trying to move a robot ONLY when a key is held.

* EDIT * Ignore this. Using a child script means that the key has to be held.

Thanks

Post Reply