Difference between revisions of "Key (event)"

From ComputerCraft Wiki
Jump to: navigation, search
(Created event page)
 
(Added example code, and copied key scan codes from Raw_key_events)
Line 6: Line 6:
 
|return1=The numerical key value of the key pressed.
 
|return1=The numerical key value of the key pressed.
 
}}
 
}}
 +
{{Example
 +
|desc=Print each key pressed on the keyboard whenever a ''key'' event is fired. Use Ctrl+T (Windows)<!--- or ???+T (Mac)---> to terminate the loop.
 +
|code=
 +
while true do
 +
  event, scancode = os.pullEvent()
 +
  print(tostring(scancode).." was pressed.")
 +
end
 +
|output=Any key that is pressed.
 +
}}
 +
==Key scan codes ==
 +
[[File:CC-Keyboard-Charcodes.png|center|frame|250x250px|Click for a larger copy of this image - contains keys and their event numbers.]]

Revision as of 00:42, 8 January 2013

This page needs some serious TLC, stat!
Please help us by cleaning it, fixing it up, or sparing it some love.
(Reason: A demonstration on the use and handling of this event would be beneficial. AfterLifeLochie 16:10, 30 November 2012 (MSK))



Grid Modem.png  Event key
Fired when any key is pressed while the terminal is focused.
Returned Object 1 The numerical key value of the key pressed.


Grid paper.png  Example
Print each key pressed on the keyboard whenever a key event is fired. Use Ctrl+T (Windows) to terminate the loop.
Code
while true do
  event, scancode = os.pullEvent()
  print(tostring(scancode).." was pressed.")
end
Output Any key that is pressed.



Key scan codes

Click for a larger copy of this image - contains keys and their event numbers.