Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How to detect single key press?

Kermit Rutkowski
Registered User
Join date: 5 Feb 2008
Posts: 8
08-02-2008 10:21
I am learning to modify the Library Kart vehicle script. The script has a “if(level & (CONTROL_DOWN))“ line that resets the script. I would like to change it so when PageDown is pressed it toggles the camera view.

The problem I encountered is when I press the PageDown key, I get 2 or 3 key presses registered and I was unable to “toggle.” I tried it on 2 different keyboards so I know it is not a malfunctioning keyboard.

Anyone with similar experience? Any work around to just accept “one” key press? It would be great to change camera view “on the fly” as I am driving the Library Kart.
Kermit Rutkowski
Registered User
Join date: 5 Feb 2008
Posts: 8
Problem solved :)
08-02-2008 10:33
Lol, I solved my own problem by using PageUp and PageDown to toggle. I guess sometimes it is good to write down the question, haha.

Interesting though that the key press is so sensitive.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
08-02-2008 13:38
I'm not sure if you'll be looking for this answer now, but the 'edges' parameter has what you want in it. A key (e.g. CONTROL_DOWN) has just been pressed down when its bit is on in levels AND edges:

(levels & edges & CONTROL_DOWN
or
(levels & CONTROL_DOWN) && (edges & CONTROL_DOWN)

A key has just been let up when its bit is off in levels but on in edges

~levels & edges & CONTROL_DOWN
or
!(levels & CONTROL_DOWN) && (edges & CONTROL_DOWN)

While the key is pressed, you'll get periodic events with the bit set in levels but not set in edges:

levels & ~edges & CONTROL_DOWN
or
(levels & CONTROL_DOWN) && !(edges & CONTROL_DOWN)