Advertisement
Derek1017

Test Key Event

Jul 13th, 2015
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.61 KB | None | 0 0
  1. local x, y = 1, 1
  2.  
  3. local xSize, ySize = term.getSize()
  4.  
  5. while true do
  6.     -- Draw a white space at the current x/y co-ord:
  7.     term.setBackgroundColor(colours.black)
  8.     term.clear()
  9.     term.setCursorPos(x, y)
  10.     term.setBackgroundColor(colours.white)
  11.     term.write(" ")
  12.    
  13.     -- Wait for a key event:
  14.     local event, key = os.pullEvent("key")
  15.    
  16.     -- Act on it:
  17.     if key == keys.up and y > 1 then
  18.         y = y - 1
  19.     elseif key == keys.down and y < ySize then
  20.         y = y + 1
  21.     elseif key == keys.left and x > 1 then
  22.         x = x - 1
  23.     elseif key == keys.right and x < xSize then
  24.         x = x + 1
  25.     elseif key == keys.q then
  26.         break
  27.     end
  28. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement