Advertisement
Theshadow989

Clock and Key Press Simultaneously

May 2nd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.88 KB | None | 0 0
  1. local function drawTime()
  2.         local x, y = term.getCursorPos()
  3.         term.setCursorPos(1,1)
  4.         write("It is "..textutils.formatTime(os.time()))
  5.         term.setCursorPos(x, y)
  6. end
  7.  
  8. local timer = os.startTimer(1)
  9. term.clear()
  10. while true do
  11.     local sEvt, arg = os.pullEvent()
  12.     if sEvt == "timer" then
  13.         if arg == timer then
  14.             timer = os.startTimer(1)
  15.             drawTime()
  16.         end
  17.   elseif sEvt == "key" or sEvt == "char" then
  18.         term.clear()
  19.         drawTime()
  20.         term.setCursorPos(1,2)
  21.         if arg == keys.down then
  22.             print("you pressed the down key")
  23.         elseif arg == keys.up then
  24.             print("you pressed the up key")
  25.         elseif arg == keys.right then
  26.             print("you pressed the right key")
  27.         elseif arg == keys.left then
  28.             print("you pressed the left key")
  29.         end
  30.   end
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement