Difference between revisions of "Os.pullEvent"
(new event discovered) |
(→Event Types) |
||
Line 59: | Line 59: | ||
! 6 | ! 6 | ||
|- | |- | ||
− | !char | + | ![[char]] |
|Fired when text is typed on the keyboard | |Fired when text is typed on the keyboard | ||
|the letter typed | |the letter typed | ||
Line 68: | Line 68: | ||
| | | | ||
|- | |- | ||
− | !key | + | ![[key]] |
|Fired when a key is pressed on the keyboard | |Fired when a key is pressed on the keyboard | ||
|numerical keycode | |numerical keycode | ||
Line 77: | Line 77: | ||
| | | | ||
|- | |- | ||
− | !timer | + | ![[timer]] |
|Fired when a timeout started by os.startTimer() completes | |Fired when a timeout started by os.startTimer() completes | ||
|Value of the timer as returned by os.startTimer() | |Value of the timer as returned by os.startTimer() | ||
Line 86: | Line 86: | ||
| | | | ||
|- | |- | ||
− | !alarm | + | ![[alarm]] |
|Fired when a time passed to os.setAlarm() is reached | |Fired when a time passed to os.setAlarm() is reached | ||
|Value of the alarm as returned by os.setAlarm() | |Value of the alarm as returned by os.setAlarm() | ||
Line 95: | Line 95: | ||
| | | | ||
|- | |- | ||
− | !redstone | + | ![[redstone]] |
|Fired when the state of any of the redstone inputs change | |Fired when the state of any of the redstone inputs change | ||
| | | | ||
Line 104: | Line 104: | ||
| | | | ||
|- | |- | ||
− | !disk | + | ![[disk]] |
|Fired when a disk is inserted into an adjacent disk drive | |Fired when a disk is inserted into an adjacent disk drive | ||
|side | |side | ||
Line 113: | Line 113: | ||
| | | | ||
|- | |- | ||
− | !disk_eject | + | ![[disk_eject]] |
|Fired when a disk is removed from an adjacent disk drive | |Fired when a disk is removed from an adjacent disk drive | ||
|side | |side | ||
Line 122: | Line 122: | ||
| | | | ||
|- | |- | ||
− | !peripheral | + | ![[peripheral]] |
|Fired when peripheral is attached | |Fired when peripheral is attached | ||
|side | |side | ||
Line 131: | Line 131: | ||
| | | | ||
|- | |- | ||
− | !peripheral_detach | + | ![[peripheral_detach]] |
|Fired when peripheral is removed | |Fired when peripheral is removed | ||
|side | |side | ||
Line 140: | Line 140: | ||
| | | | ||
|- | |- | ||
− | !rednet_message | + | ![[rednet_message]] |
|Fired when a rednet message is received from the [[Rednet_(API)|rednet API]] | |Fired when a rednet message is received from the [[Rednet_(API)|rednet API]] | ||
|senderID | |senderID | ||
Line 149: | Line 149: | ||
| | | | ||
|- | |- | ||
− | !http_success | + | ![[http_success]] |
|Fired when an attempt to recieve text from / post text on a website is successful | |Fired when an attempt to recieve text from / post text on a website is successful | ||
|url of the site | |url of the site | ||
Line 158: | Line 158: | ||
| | | | ||
|- | |- | ||
− | !http_failure | + | ![[http_failure]] |
|Fired when an attempt to recieve text from / post text on a website is unsuccessful | |Fired when an attempt to recieve text from / post text on a website is unsuccessful | ||
|url of the site | |url of the site | ||
Line 167: | Line 167: | ||
| | | | ||
|- | |- | ||
− | !mouse_click | + | ![[mouse_click]] |
|Fired when a mouse button is pressed | |Fired when a mouse button is pressed | ||
|mouse button | |mouse button | ||
Line 176: | Line 176: | ||
| | | | ||
|- | |- | ||
− | !mouse_scroll | + | ![[mouse_scroll]] |
|Fired when a mousewheel is scrolled. | |Fired when a mousewheel is scrolled. | ||
|scroll direction (-1 for up, 1 for down) | |scroll direction (-1 for up, 1 for down) | ||
Line 184: | Line 184: | ||
| | | | ||
|- | |- | ||
− | !mouse_drag | + | ![[mouse_drag]] |
|Fired when the mouse is moved after clicking. | |Fired when the mouse is moved after clicking. | ||
|x coordinate | |x coordinate |
Revision as of 04:42, 4 November 2012
Function os.pullEvent | |
Yields computer until event occurs | |
Syntax | os.pullEvent(string only-event-to-accept) |
Returns | event, parameters |
Part of | ComputerCraft |
API | os |
Examples
Example | |
The program requires to wait for a keypress to do something: | |
Code |
function clear() term.clear() term.setCursorPos (1,1) end while true do clear() print ("Press E to do something.") local event, param1 = os.pullEvent ("char") -- limit os.pullEvent to the char event if param1 == "e" then -- if the returned value was 'e' clear() write ("Name: ") local name = read() print (name) break else clear() print ("Wrong button!") sleep (1.5) -- I don't like a whole 2 seconds but 1 second is too short end end |
How it Works
When os.pullEvent() is called, regardless of whether it has variables to set, the computer is yielded until an event occurs. An event is anything the computer can use as input, such as a button being pushed on the keyboard or a redstone input. When said event occurs, the event's name is placed in the first variable (the variable 'event' in the section below). With the event comes returned values, and, depending on the event type, there can be different amounts and different data types of returned values.
For example, the event "char" returns "char" as the event and (let's say E was pressed) the first parameter will be set to "e", although whether or not Shift was pressed can change that "e" to an "E" as well.
The event "redstone" only returns the event type since any other information needed can be retrieved with redstone.getInput.
Common Syntax
event, param1, param2, param3 = os.pullEvent()
Event Types
Name | Description | Parameters | |||||
---|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | ||
char | Fired when text is typed on the keyboard | the letter typed | |||||
key | Fired when a key is pressed on the keyboard | numerical keycode | |||||
timer | Fired when a timeout started by os.startTimer() completes | Value of the timer as returned by os.startTimer() | |||||
alarm | Fired when a time passed to os.setAlarm() is reached | Value of the alarm as returned by os.setAlarm() | |||||
redstone | Fired when the state of any of the redstone inputs change | ||||||
disk | Fired when a disk is inserted into an adjacent disk drive | side | |||||
disk_eject | Fired when a disk is removed from an adjacent disk drive | side | |||||
peripheral | Fired when peripheral is attached | side | |||||
peripheral_detach | Fired when peripheral is removed | side | |||||
rednet_message | Fired when a rednet message is received from the rednet API | senderID | message | distanceTravelled | |||
http_success | Fired when an attempt to recieve text from / post text on a website is successful | url of the site | text on the site | ||||
http_failure | Fired when an attempt to recieve text from / post text on a website is unsuccessful | url of the site | |||||
mouse_click | Fired when a mouse button is pressed | mouse button | x coordinate | y coordinate | |||
mouse_scroll | Fired when a mousewheel is scrolled. | scroll direction (-1 for up, 1 for down) | x coordinate | y coordinate | |||
mouse_drag | Fired when the mouse is moved after clicking. | x coordinate | y coordinate |