Advertisement
Guest User

keytest

a guest
Jan 15th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.84 KB | None | 0 0
  1.  
  2. --setup for key handlers
  3. local event = require "event" -- load event table and store the pointer to it in event
  4. local term = require "term"
  5. ship = component.warpdriveShipController
  6. local char_w = string.byte("w") -- numerical representation of the space char
  7. local char_s = string.byte("s")
  8. local char_e = string.byte("e")
  9. local char_p = string.byte("p")
  10. local running = true -- state variable so the loop can terminate
  11.  --print("Press W to close and S to say SLUT E to enter text P to Vomit it back")
  12. function unknownEvent()
  13.   -- do nothing if the event wasn't relevant
  14. end
  15. --end key handler setup
  16. --begin main code
  17. function mainmenu()
  18. term.clear()
  19. print("Press - to operate ship")
  20. end
  21.  
  22.  
  23.  
  24. --main code ends here
  25. --key handlers begin here
  26. -- table that holds all event handlers
  27. -- in case no match can be found returns the dummy function unknownEvent
  28. local myEventHandlers = setmetatable({}, { __index = function() return unknownEvent end })
  29.  
  30. -- Example key-handler that simply sets running to false if the user hits space
  31. function myEventHandlers.key_up(adress, char, code, playerName)
  32.   if (char == char_w) then
  33.     running = false
  34. elseif (char == char_s) then
  35. print("you pressed the s key slut")
  36. elseif (char == char_e) then print("Enter Some Text") j = io.read() print("input Accepted")
  37. elseif (char== char_p) then print("Computer Vomit:", j) mainmenu()
  38.   end
  39. end
  40.  
  41. -- The main event handler as function to separate eventID from the remaining arguments
  42. function handleEvent(eventID, ...)
  43.   if (eventID) then -- can be nil if no event was pulled for some time
  44.     myEventHandlers[eventID](...) -- call the appropriate event handler with all remaining arguments
  45.   end
  46. end
  47.  
  48. -- main event loop which processes all events, or sleeps if there is nothing to do
  49. while running do
  50.   handleEvent(event.pull()) -- sleeps until an event is available, then process it
  51. end
  52. --end key handlers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement