Difference between revisions of "Os.pullEvent"
(added new event and removed three unused columns from the table - please note: even though os.pullEvent() CAN return up to 6 parameters, none of the default events causes it to do so) |
|||
Line 50: | Line 50: | ||
! rowspan="2" | Name | ! rowspan="2" | Name | ||
! rowspan="2" | Description | ! rowspan="2" | Description | ||
− | ! colspan=" | + | ! colspan="3" | Parameters |
|- | |- | ||
! 1 | ! 1 | ||
! 2 | ! 2 | ||
! 3 | ! 3 | ||
− | |||
− | |||
− | |||
|- | |- | ||
![[char]] | ![[char]] | ||
|Fired when text is typed on the keyboard | |Fired when text is typed on the keyboard | ||
|(string)the letter typed | |(string)the letter typed | ||
− | |||
− | |||
− | |||
| | | | ||
| | | | ||
Line 71: | Line 65: | ||
|Fired when a key is pressed on the keyboard | |Fired when a key is pressed on the keyboard | ||
|(number)numerical keycode | |(number)numerical keycode | ||
− | |||
− | |||
− | |||
| | | | ||
| | | | ||
Line 80: | Line 71: | ||
|Fired when a timeout started by os.startTimer() completes | |Fired when a timeout started by os.startTimer() completes | ||
|(number)Value of the timer as returned by os.startTimer() | |(number)Value of the timer as returned by os.startTimer() | ||
− | |||
− | |||
− | |||
| | | | ||
| | | | ||
Line 89: | Line 77: | ||
|Fired when a time passed to os.setAlarm() is reached | |Fired when a time passed to os.setAlarm() is reached | ||
|(number)Value of the alarm as returned by os.setAlarm() | |(number)Value of the alarm as returned by os.setAlarm() | ||
− | |||
− | |||
− | |||
| | | | ||
| | | | ||
Line 100: | Line 85: | ||
| | | | ||
| | | | ||
+ | |- | ||
+ | ![[terminate]] | ||
+ | |Fired when a combination of keys CTRL and T is pressed and held for three seconds. It is handled by default by os.pullEvent() and causes calling of two other functions: error() - To terminate the program; and print() to inform the user that the program he or she was running has been terminated. | ||
| | | | ||
| | | | ||
Line 107: | Line 95: | ||
|Fired when a disk is inserted into an adjacent disk drive | |Fired when a disk is inserted into an adjacent disk drive | ||
|(string)side | |(string)side | ||
− | |||
− | |||
− | |||
| | | | ||
| | | | ||
Line 116: | Line 101: | ||
|Fired when a disk is removed from an adjacent disk drive | |Fired when a disk is removed from an adjacent disk drive | ||
|(string)side | |(string)side | ||
− | |||
− | |||
− | |||
| | | | ||
| | | | ||
Line 125: | Line 107: | ||
|Fired when peripheral is attached | |Fired when peripheral is attached | ||
|(string)side | |(string)side | ||
− | |||
− | |||
− | |||
| | | | ||
| | | | ||
Line 134: | Line 113: | ||
|Fired when peripheral is removed | |Fired when peripheral is removed | ||
|(string)side | |(string)side | ||
− | |||
− | |||
− | |||
| | | | ||
| | | | ||
Line 145: | Line 121: | ||
|(string)message | |(string)message | ||
|(number)distance travelled | |(number)distance travelled | ||
− | |||
− | |||
− | |||
|- | |- | ||
![[http_success]] | ![[http_success]] | ||
Line 153: | Line 126: | ||
|(string)url of the site | |(string)url of the site | ||
|(table)text on the site | |(table)text on the site | ||
− | |||
− | |||
− | |||
| | | | ||
|- | |- | ||
Line 161: | Line 131: | ||
|Fired when an attempt to receive text from / post text on a website is unsuccessful | |Fired when an attempt to receive text from / post text on a website is unsuccessful | ||
|(string)url of the site | |(string)url of the site | ||
− | |||
− | |||
− | |||
| | | | ||
| | | | ||
Line 172: | Line 139: | ||
|(number)x coordinate | |(number)x coordinate | ||
|(number)y coordinate | |(number)y coordinate | ||
− | |||
− | |||
− | |||
|- | |- | ||
![[mouse_scroll]] | ![[mouse_scroll]] | ||
Line 181: | Line 145: | ||
|(number)x coordinate(in screen chars) | |(number)x coordinate(in screen chars) | ||
|(number)y coordinate(in screen chars) | |(number)y coordinate(in screen chars) | ||
− | |||
− | |||
|- | |- | ||
![[mouse_drag]] | ![[mouse_drag]] | ||
Line 188: | Line 150: | ||
|(number)x coordinate(in screen chars) | |(number)x coordinate(in screen chars) | ||
|(number)y coordinate(in screen chars) | |(number)y coordinate(in screen chars) | ||
− | |||
− | |||
| | | | ||
|} | |} |
Revision as of 10:31, 8 November 2012
Function os.pullEvent | |
Yields computer until event occurs | |
Syntax | os.pullEvent((string) only-event-to-accept) |
Returns | (string)event, variable parameters(see table below) |
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 | ||
char | Fired when text is typed on the keyboard | (string)the letter typed | ||
key | Fired when a key is pressed on the keyboard | (number)numerical keycode | ||
timer | Fired when a timeout started by os.startTimer() completes | (number)Value of the timer as returned by os.startTimer() | ||
alarm | Fired when a time passed to os.setAlarm() is reached | (number)Value of the alarm as returned by os.setAlarm() | ||
redstone | Fired when the state of any of the redstone inputs change | |||
terminate | Fired when a combination of keys CTRL and T is pressed and held for three seconds. It is handled by default by os.pullEvent() and causes calling of two other functions: error() - To terminate the program; and print() to inform the user that the program he or she was running has been terminated. | |||
disk | Fired when a disk is inserted into an adjacent disk drive | (string)side | ||
disk_eject | Fired when a disk is removed from an adjacent disk drive | (string)side | ||
peripheral | Fired when peripheral is attached | (string)side | ||
peripheral_detach | Fired when peripheral is removed | (string)side | ||
rednet_message | Fired when a rednet message is received from the rednet API | (number)senderID | (string)message | (number)distance travelled |
http_success | Fired when an attempt to receieve text from / post text on a website is successful | (string)url of the site | (table)text on the site | |
http_failure | Fired when an attempt to receive text from / post text on a website is unsuccessful | (string)url of the site | ||
mouse_click | Fired when a mouse button is pressed | (number)mouse button | (number)x coordinate | (number)y coordinate |
mouse_scroll | Fired when a mousewheel is scrolled. | (number)scroll direction (-1 for up, 1 for down) | (number)x coordinate(in screen chars) | (number)y coordinate(in screen chars) |
mouse_drag | Fired when the mouse is moved after clicking. | (number)x coordinate(in screen chars) | (number)y coordinate(in screen chars) |