key event

From ComputerCraft
Jump to: navigation, search
key
Event
Returns
  • keycode : number The keycode of the key being pressed
  • held : boolean Wether or not the key was already pressed earlier and is currently being held down

Source CC:Tweaked

Occurs every time the user presses down a key or when a key is being repeated because it's being held down.

ExampleExampleUsing key event
Showing what key the user is interacting with and telling if it's being held down.
Code
while true do
  local event, key_code, being_hold = os.pullEvent("key")

  if being_hold then
    print("The player is holding", keys.getName(key_code), "down.")
  else
    print("The player pressed", keys.getName(key_code))
end