Key (event)

From ComputerCraft Wiki
Jump to: navigation, search



Grid Modem.png  Event key
Fired when any key except Escape 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
  local event, scancode = os.pullEvent("key")
  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.

These scan codes are also available as constants in the keys API, and can be translated from numerical codes to strings using keys.getName.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox