GetJoystick
 
从附加的游戏设备读取按钮和轴信息

语法

Declare Function GetJoystick ( ByVal id As Integer, ByRef buttons As Integer = 0, ByRef a1 As Single = 0, ByRef a2 As Single = 0, ByRef a3 As Single = 0, ByRef a4 As Single = 0, ByRef a5 As Single = 0, ByRef a6 As Single = 0, ByRef a7 As Single = 0, ByRef a8 As Single = 0 ) As Integer

用法

result = GetJoystick( id [, buttons [, a1 [, a2 [, a3 [, a4 [, a5 [, a6 [, a7 [, a8 ]]]]]]]]] )

参数

id
设备ID号(0 - 15)
buttons
按钮状态
a1
第一轴值
a2
第二轴值
a3
第三轴值
a4
第四轴值
a5
第五轴值
a6
第六轴值
a7
第七轴值
a8
第八轴值

返回值

0成功或1失败。所有轴位置都以浮点格式返回。

说明

GetJoystick将检索按钮状态,以及最多8个轴的轴位置,由id 确定的操纵杆,015之间的数字。按照与GetMouse类似的方式存储按钮,buttons 中的每一位表示一个按钮。

返回每个有效轴的-1.01.0之间的单个精度值。如果控制器不存在轴,则返回值-1000.00.

GetJoystick将在成功完成后返回0失败后返回1.可以通过指定非法的操纵杆号码,指定不存在的操纵杆或操纵杆API中的故障引起故障。

例子

Screen 12

Dim x As Single
Dim y As Single
Dim buttons As Integer
Dim result As Integer
Dim a As Integer

Const JoystickID = 0

'这一行检查看看操纵杆是否正常。

If GetJoystick(JoystickID,buttons,x,y) Then 
    Print "操纵杆不存在或操纵杆错误。"
    Print
    Print "按任意键继续。"
    Sleep
    End
End If


Do
    result = GetJoystick(JoystickID,buttons,x,y)

    Locate 1,1
    Print ;"结果:";result;"x:" ;x;"y:";y;"纽扣:";buttons,"","",""
    
    '这将测试按1到27按钮。
    For a = 0 To 26 
        If (buttons And (1 Shl a)) Then 
            Print "按键";a;"按下。"
        Else 
            Print "按键";a;"没有按。"
        End If
    Next a
Loop


方言差异

  • -lang qb 方言中不可用,除非使用别名__Getjoystick引用。

与QB差别

  • 新的FreeBASIC

参考