Advertisement
theoriginalbit

CCKeyboard — Example

Mar 24th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.50 KB | None | 0 0
  1. os.loadAPI('keyboard')
  2.  
  3. keyboard.setup('left')
  4.  
  5. local display = ''
  6.  
  7. keyboard.render()
  8.  
  9. while true do  
  10.   term.setCursorPos(1,1)
  11.   print((display or 'nil')..' ')
  12.  
  13.   local event = { keyboard.pullEvent() }
  14.  
  15.   if event[1] == 'char' then
  16.     display = display..event[2]
  17.   elseif event[1] == 'key' then
  18.     if event[2] == keys.backspace then
  19.       display = display:sub(1, #display - 1)
  20.     elseif event[1] == keys.enter then
  21.       display = display..'\n'
  22.     end
  23.   end
  24.  
  25.   keyboard.render()
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement