Advertisement
Rakoonic

key input module

Sep 16th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.97 KB | None | 0 0
  1. --------------------------------------------------------------
  2. -- KEY INPUT LIBRARY -----------------------------------------
  3.  
  4. local storyboard = require( "storyboard" )
  5. local socket     = require('socket')
  6.  
  7. local class = {}
  8.  
  9. --------------------------------------------------------------
  10. -- FUNCTIONS -------------------------------------------------
  11.  
  12. function class.initialise()
  13.  
  14.     local udp = socket.udp()
  15.     udp:setsockname('127.0.0.1', 5000)
  16.     udp:settimeout(0.001)
  17.     local char, ip, port
  18.     timer.performWithDelay(
  19.         200,
  20.         function ()
  21.             char, ip, port = udp:receivefrom()
  22.             print( "OI", char, ip, port, "blah" )
  23.             if char then
  24.                 local scene = storyboard.getScene( storyboard.getCurrentSceneName() )
  25.                 if type( scene.keyboardPressed ) == 'function' then scene:keyboardPressed( char ) ; end
  26.             end
  27.         end,
  28.         0
  29.     )
  30.  
  31. end
  32.  
  33. --------------------------------------------------------------
  34. -- RETURN CLASS DEFINITION -----------------------------------
  35.  
  36. return class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement