Advertisement
Guest User

Untitled

a guest
Jun 9th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. local function onKeyDown(char, code)
  2. if code == keyboard.keys.back and not readonly then
  3. if left() then
  4. delete()
  5. end
  6. elseif code == keyboard.keys.delete and not readonly then
  7. delete()
  8. elseif code == keyboard.keys.left then
  9. left()
  10. elseif code == keyboard.keys.right then
  11. right()
  12. elseif code == keyboard.keys.home then
  13. home()
  14. elseif code == keyboard.keys["end"] then
  15. ende()
  16. elseif code == keyboard.keys.up then
  17. up()
  18. elseif code == keyboard.keys.down then
  19. down()
  20. elseif code == keyboard.keys.pageUp then
  21. local w, h = getSize()
  22. up(h - 1)
  23. elseif code == keyboard.keys.pageDown then
  24. local w, h = getSize()
  25. down(h - 1)
  26. elseif code == keyboard.keys.enter and not readonly then
  27. enter()
  28. elseif readonly and code == keyboard.keys.q then
  29. running = false
  30. elseif not keyboard.isControl(char) and not readonly then
  31. insert(unicode.char(char))
  32. end
  33. end
  34.  
  35.  
  36. while running do
  37. local event, address, arg1, arg2, arg3 = event.pull() -- arg1 equates to char, arg2 is code in the onKeyDown() function
  38. if type(address) == "string" and component.isPrimary(address) then
  39. local blink = true
  40. if event == "key_down" then
  41. onKeyDown(arg1, arg2)
  42. else
  43. blink = false
  44. end
  45. if blink then
  46. term.setCursorBlink(true)
  47. term.setCursorBlink(true) -- force toggle to caret
  48. end
  49. end
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement