key event

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

ExampleUsing key event
Showing what key the user is interacting with and telling if it's being held down.
Code
<nowiki>
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
    </nowiki>
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
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.