--------------------------------------------------- 
-- FBA Tutorials
--
-- Tutorial / 05 / Handling Input
--
--------------------------------------------------- 
--
-- This example will show you how to get stylus and buttons input
--
--------------------------------------------------- 



function onmainloop()	
         clear(0,0,0)
         
         --
         -- GET KEYS INPUT
         --
         -- numkeypress(x)
         -- tell you how many times the key with ASCII code "x" has been pressed until last pression. If it returns 0, the key
         -- is not pressed!
         --
         -- keyleft(), keyright(), keyup(), keydown()
         -- keyfire1(), keyfire2(), keyfire3()
         --
         -- are costants that identify keypress codes for: left, right, up, down, fire1, fire2, fire3 buttons
         -- you should use this to check for key directions instead of ASCII codes
         --
         numleft = numkeypress( keyleft() )
         numright = numkeypress( keyright() )
         numdown = numkeypress( keydown() )
         numup = numkeypress( keyup() )
         numfire1 = numkeypress( keyfire1() )
         numfire2 = numkeypress( keyfire2() )
         numfire3 = numkeypress( keyfire3() )
         
         print(10, 20, "LEFT COUNT: " .. numleft, 255, 0, 0)
         if numleft > 0 then 
            print(100,20,"LEFT PRESSED!", 0,255,0)
         end;
         
         print(10, 40, "RIGHT COUNT: " .. numright, 255, 0, 0)
         if numright > 0 then 
            print(100,40,"RIGHT PRESSED!", 0,255,0)
         end;
         
         print(10, 60, "UP COUNT: " .. numup, 255, 0, 0)
         if numup > 0 then 
            print(100,60,"UP PRESSED!", 0,255,0)
         end;

         
         print(10, 80, "DOWN COUNT: " .. numdown, 255, 0, 0)
         if numdown > 0 then 
            print(100,80,"DOWN PRESSED!", 0,255,0)
         end;
         
         print(10, 100, "FIRE1 COUNT: " .. numfire1, 255, 0, 0)
         if numfire1 > 0 then 
            print(100,100,"FIRE1 PRESSED!", 0,255,0)
         end;
         
         print(10, 120, "FIRE2 COUNT: " .. numfire2, 255, 0, 0)
         if numfire2 > 0 then 
            print(100,120,"FIRE2 PRESSED!", 0,255,0)
         end;
         
         print(10, 140, "FIRE3 COUNT: " .. numfire3, 255, 0, 0)
         if numfire3 > 0 then 
            print(100,140,"FIRE3 PRESSED!", 0,255,0)
         end;
         
         --
         -- GET STYLUS/MOUSE INPUT
         --
         mx=mousex()
         my=mousey()
         print(10,160,"MOUSE POSITION: " .. mx .. "," ..my, 0,0,255)
         if mousedown() > 0 then
            print(140,160,"MOUSE IS DOWN!", 255,255,0)
         else
            print(140,160,"MOUSE IS UP!", 255,255,0)
         end;         

end
