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

[easy lame-o question everyone knows] On key input

Started by HelloThere, 27 December 2012 - 04:45 PM
HelloThere #1
Posted 27 December 2012 - 05:45 PM
right, i know this is a lame-o question you all know, but how can i make it so something happens when someone hits a key…

I was pretty sure it went along the lines of


local input = os.pullEvent("key")
if input == "28" then

{code}


But that dosen't seem to work.

Help?
Luanub #2
Posted 27 December 2012 - 05:50 PM
os.pullEvent() returns the following, event type, param1, param2, param3, param4, and param5.

With they key events it only uses param1 so to capture the key pressed do..

local event, input = os.pullEvent("key")
HelloThere #3
Posted 27 December 2012 - 06:04 PM
Ohh i was so close!

Thanks for the help! Heroes like you save the day :D/>
ChunLing #4
Posted 27 December 2012 - 10:47 PM
Note that also makes it so that nothing will happen until someone hits a key.

You can also pull events without specifying the event to pull, by not passing anything to the function. This makes it so that the program can continue on receiving any event type, and you can sort out how to respond (or whether to respond) to whatever event you get.