Difference between revisions of "Char (event)"

From ComputerCraft Wiki
Jump to: navigation, search
m (NeedsWork resolved.)
m (better coding habits)
 
Line 8: Line 8:
 
|code=
 
|code=
 
  while true do
 
  while true do
   event, character = os.pullEvent("char")
+
   local event, character = os.pullEvent("char")
 
   print(character.." was pressed.")
 
   print(character.." was pressed.")
 
  end
 
  end
 
|output=The key that was pressed. Note this doesn't trigger for Tab, Shift, the up arrow, etc. Use the [[key_(event)|key]] event if you wish to trap those keys.
 
|output=The key that was pressed. Note this doesn't trigger for Tab, Shift, the up arrow, etc. Use the [[key_(event)|key]] event if you wish to trap those keys.
 
}}
 
}}

Latest revision as of 09:30, 28 October 2013



Grid Modem.png  Event char
Fired when a alphanumeric key is pressed on the keyboard.
Returned Object 1 The String representing the character that was pressed.


Grid paper.png  Example
Prints out the character that was pressed.
Code
while true do
  local event, character = os.pullEvent("char")
  print(character.." was pressed.")
end
Output The key that was pressed. Note this doesn't trigger for Tab, Shift, the up arrow, etc. Use the key event if you wish to trap those keys.