' Rapid-Q by William Yu (c)1999-2000 . ' ================================================================================ ' Upload_il_tuo_script_su_Rapidq.it ' QJoystick ****** ****** A simple component based on a RapidQ example. There are not many functions, but it works. It has been tested with Windows 98SE, and a Creative Cobra USB Gamepad. ***** QJoystick Properties ***** Name Type Description Joystick ID ID LONG 0 - Joystick 1 1 - Joystick 2 RefreshRate INTEGER Polling frequency in millisec. Default value is 10, meaning joystick position is checked 100 times/sec QJoystick can support up to 32 buttons. ButtonMap is a ButtonMap STRING string representig the pressed buttons. An easy way to see if a button has been pressed is using the Pressed method Enabled LONG Starts/Stops QJoystick polling ***** QJoystick Methods ***** Name Type Parameters Description Check if a button has been pressed. Pressed FUNCTION BtnNumber AS INTEGER Returns 1 if the button has been pressed, 0 otherwise. You can use it as a BOOL in IF constructs. ***** QJoystick Events ***** Event Occurs when Parameters Description Depending on how the Joystick L as LONG is moved, function parameters R as LONG turn to 1. OnMove Joystick is moved D as LONG Ex. When the joystick is moved U as LONG toward the upper left corner L and U will turn to 1, while R and D will remain 0. OnBtnPress A button is pressed BtnMap as STRING See below ***** The Button Map ***** QJoystick can support up to 32 buttons. Whenever a button is pressed, the OnBtnPress function will return a BtnMap string representing all of the 32 buttons status. Pressed buttons will be represented by "1". Some examples: BtnString Meaning 10000000000000000000000000000000 You have pressed button 1 00100000000000000000000000000000 You have pressed button 3 10010000000000000000000000000000 You have pressed button 1 and 4 together Since BtnString analysis may be boring, you can use the Pressed method to check if a button has been pressed. ***** QJoystickExample ***** ' A simple example. Try clicking button 1, or button 2, or button 3 ' or buttons 1 and 2 together. $typecheck ON $Include "QJoystick.inc" Declare Sub joyMove (L as Long, R as long, D as long, U as long) Declare Sub Buttons (BtnMap as string) dim Joy as qjoystick Joy.enabled = 1 Joy.OnMove = joyMove Joy.OnBtnPress = Buttons Joy.RefreshRate = 5 ' When you change RefreshRate, you have to re-set "Enabled" to 1 Joy.enabled = 1 CREATE FORM as qform Center borderstyle = 3 font.name = "Courier new" create CURS AS QLABEL caption = ":-)" top = 120 left = 100 font.size = 12 END CREATE CREATE BUTTONSLIST as qedit align = 2 END CREATE END CREATE Form.showmodal sub joymove (L as Long, R as long, D as long, U as long) if L = 1 then CURS.left = CURS.left - 4 if R = 1 then CURS.left = CURS.left + 4 if D = 1 then CURS.top = CURS.top + 4 if U = 1 then CURS.top = CURS.top - 4 end sub Sub Buttons (BtnMap as string) BUTTONSLIST.text = Joy.ButtonMap If Joy.Pressed(3) then Curs.caption = ":-p" elseIf Joy.Pressed(1) AND Joy.Pressed(2) then CURS.caption = ";-)" elseIf Joy.Pressed(2) then Curs.caption = ":-)" else CURS.caption = ":-(" End if end sub ' =============================================================================== ' 2003 Holyguard.net - 2007_Abruzzoweb