Guidance
指路人
g.yi.org
software / rapidq / Examples / Devices / joystick / QJoystick / QJoystick.htm

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
QJoystick Component

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
ID LONG Joystick ID
0 - Joystick 1
1 - Joystick 2
RefreshRate INTEGER Polling frequency in millisec. Default value is 10, meaning joystick position is checked 100 times/sec
ButtonMap STRING QJoystick can support up to 32 buttons. ButtonMap is a 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
Pressed FUNCTION BtnNumber AS INTEGER Check if a button has been pressed. 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
OnMove Joystick is moved

L as LONG
R as LONG
D as LONG
U as LONG

Depending on how the Joystick is moved, function parameters turn to 1.

Ex. When the joystick is moved 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

 

 

 

掌柜推荐
 
 
¥1,800.00 ·
 
 
¥489.00 ·
 
 
¥288.00 ·
 
 
¥908.00 ·
 
 
¥748.00 ·
 
 
¥264.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2004-01-29 05:13:17