Posted 11 March 2015 - 12:21 AM
How do i use the pullevent thing for getting keyboard input! examples would be helpful.
Edited on 10 March 2015 - 11:35 PM
function os.pullEventRaw( sFilter )
return coroutine.yield( sFilter )
end
function os.pullEvent( sFilter )
local eventData = { os.pullEventRaw( sFilter ) }
if eventData[1] == "terminate" then
error( "Terminated", 0 )
end
return unpack( eventData )
end
local eve,key=os.pullEvent("key")
if key==keys.backspace then --Would trigger if the user hit the backspace key
doBackspaceStuff()
end
I would recommend looking at the keyAPI for the available key variables, or the key Event for a list of which keys return which numbers.
local eve,key=os.pullEvent()
if eve=="key" then --Will trigger everytime the user presses a key
if key==keys.backspace then
doBackspaceStuff()
else
otherKeystuff()
end
elseif eve=="char" then --Will trigger whenever the user presses a key that is printable (a-z,0-9,!@#$%,etc.)
print("I just pressed "..key)
end
They char event is thrown if you press a key that is printable, however the key event is always thrown.Well, you would most likely be using os.pullEvent instead of os.pullEventRaw (however raw is almost exactly the same except it can catch the Terminate event)
But if you wanted to get a keyboard key you could go about it like soI would recommend looking at the keyAPI for the available key variables, or the key Event for a list of which keys return which numbers.local eve,key=os.pullEvent("key") if key==keys.backspace then --Would trigger if the user hit the backspace key doBackspaceStuff() end
If you wanted to get a little more complex you could doThey char event is thrown if you press a key that is printable, however the key event is always thrown.local eve,key=os.pullEvent() if eve=="key" then --Will trigger everytime the user presses a key if key==keys.backspace then doBackspaceStuff() else otherKeystuff() end elseif eve=="char" then --Will trigger whenever the user presses a key that is printable (a-z,0-9,!@#$%,etc.) print("I just pressed "..key) end
Meaning, if I press X both a key and char event are created, but if i press backspace, only a key event is created.
Keep in mind that if you use pullEventRaw, terminate will go though any filter, so if you have os.pullEventRaw("key"), terminate will still pass as an event.
Thank you guys so much that was very helpful!!It's very similar to the normal pull event if I recall correctly. the only difference is the normal one reacts to terminate events
for reference here is the bios.lua for CC 1.73 ~line 130function os.pullEventRaw( sFilter ) return coroutine.yield( sFilter ) end function os.pullEvent( sFilter ) local eventData = { os.pullEventRaw( sFilter ) } if eventData[1] == "terminate" then error( "Terminated", 0 ) end return unpack( eventData ) end
reading the above code, I can't see why you can't use the same inputs/outputs that you would use for the normal pull event
Thank you.This may help too, http://www.computerc...3-event-basics/