This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
GeneralSocrates's profile picture

If key is pressed, not key event

Started by GeneralSocrates, 02 June 2013 - 11:01 AM
GeneralSocrates #1
Posted 02 June 2013 - 01:01 PM
I've been looking around a lot for this but I haven't found anything…
I've come up with an idea that would require me to check pressed keys on startup.

Note that I do not mean a key event, since the key would ALREADY be pressed and thus no event is triggered on startup.
I'm more like looking for a condition that would be translatable by "if key is pressed, then"

Any ideas?
Lyqyd #2
Posted 03 June 2013 - 12:44 PM
Split into new topic.

It is not currently possible to determine the current state of a given key. However, keys that are held down continue to throw key events while they are held down. You could use a short timer to see if one of these events come in at startup.
GopherAtl #3
Posted 03 June 2013 - 04:48 PM
Just a minor clarification, only the last key pressed repeats while held. Not all held keys, and not the earliest pressed of those currently held; only the last one pressed. Ex.

Press and hold A, you get repeating A events; while still holding that, press and hold B, you now get repeating B events. Release B, you stop getting repeating events entirely. You do not resume getting A events. You can see this behavior easily by running "while true do print(os.pullEvent()) end" at a lua prompt.