Guest User

Untitled

a guest
Oct 3rd, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | None | 0 0
  1. local computer = require("computer")
  2. local component = require("component")
  3. local redstone = component.redstone
  4. local debug = component.debug
  5. local event = require ("event")
  6. local keyboard = require("keyboard")
  7. local keys = keyboard.keys
  8.  
  9. local function getKeyPress()
  10.   local _, _, _, keycode = event.pull(0.1, "key_down")
  11.   return keys[keycode]
  12. end
  13.  
  14. local char_space = string.byte(" ")
  15. local char_a = string.byte("a")
  16. local char_b = string.byte("b")
  17. local runningA = true
  18.  
  19.  
  20. function unknownEvent()
  21.  
  22. end
  23.  
  24. local myEventHandlers = setmetatable({}, {__index = function() return unknownEvent end})
  25.  
  26. function myEventHandlers.key_up(adress, char, code, playerName)
  27.   if (char == char_space) then
  28.     runningA = false
  29.   end
  30.   if (char == char_a) then
  31.     runCmd("set timer 20000", "set timer 10000", 10, 10)
  32.   end
  33.   if (char == char_b) then
  34.     runningB = false
  35.   end
  36. end
  37.  
  38. function handleEvent(eventID, ...)
  39.   if (eventID) then
  40.     myEventHandlers[eventID](...)
  41.   end
  42. end
  43.  
  44. function exit()
  45.   os.exit()
  46. end
  47.  
  48. function runCmd(cmd1, cmd2, sleep, repeat)
  49.   i = 0
  50.   while i <= repeat do
  51.     debug.runCommand(cmd1)
  52.     os.sleep(sleep)
  53.     debug.runCommand(cmd2)
  54.     os.sleep(sleep)
  55.     i = i + 1
  56.   end
  57. end
  58.  
  59. while runningA do
  60.   handleEvent(event.pull())
  61. end
Advertisement
Add Comment
Please, Sign In to add comment