Guidance
指路人
g.yi.org
software / rapidq / Examples / Devices / joystick / Joystick / joystick.bas

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

  
' Joystick routines

     $TYPECHECK ON

     CONST JOYSTICKID1 = 0
     CONST JOYSTICKID2 = 1

     CONST JOY_POVCENTERED = -1
     CONST JOY_POVFORWARD = 0
     CONST JOY_POVRIGHT = 9000
     CONST JOY_POVLEFT = 27000
     CONST JOY_RETURNX = &H1
     CONST JOY_RETURNY = &H2
     CONST JOY_RETURNZ = &H4
     CONST JOY_RETURNR = &H8
     CONST JOY_RETURNU = &H10
     CONST JOY_RETURNV = &H20
     CONST JOY_RETURNPOV = &H40
     CONST JOY_RETURNBUTTONS = &H80
     CONST JOY_RETURNRAWDATA = &H100
     CONST JOY_RETURNPOVCTS = &H200
     CONST JOY_RETURNCENTERED = &H400
     CONST JOY_USEDEADZONE = &H800
     CONST JOY_RETURNALL = JOY_RETURNX OR JOY_RETURNY OR JOY_RETURNZ OR JOY_RETURNR OR JOY_RETURNU OR JOY_RETURNV OR JOY_RETURNPOV OR JOY_RETURNBUTTONS
     CONST JOY_CAL_READALWAYS = &H10000
     CONST JOY_CAL_READRONLY = &H2000000
     CONST JOY_CAL_READ3 = &H40000
     CONST JOY_CAL_READ4 = &H80000
     CONST JOY_CAL_READXONLY = &H100000
     CONST JOY_CAL_READYONLY = &H200000
     CONST JOY_CAL_READ5 = &H400000
     CONST JOY_CAL_READ6 = &H800000
     CONST JOY_CAL_READZONLY = &H1000000
     CONST JOY_CAL_READUONLY = &H4000000
     CONST JOY_CAL_READVONLY = &H8000000

     CONST JOY_OFFSET = 10000

     TYPE TJOYINFOEX
      dwSize AS LONG
      dwFlags AS LONG
      dwXpos AS LONG
      dwYpos AS LONG
      dwZpos AS LONG
      dwRpos AS LONG
      dwUpos AS LONG
      dwVpos AS LONG
      dwButtons AS LONG
      dwButtonNubmer AS LONG
      dwPOV AS LONG
      dwReserved1 AS LONG
      dwReserved2 AS LONG
     END TYPE


     DECLARE FUNCTION JoyGetPosEx LIB "WINMM" ALIAS "joyGetPosEx" _
      (uJoyID AS LONG, JoyInfo AS TJOYINFOEX) AS LONG
     DECLARE FUNCTION JoyReleaseCapture LIB "WINMM" ALIAS "joyReleaseCapture" _
      (uJoyID AS LONG) AS LONG
     DECLARE FUNCTION JoySetCapture LIB "WINMM" ALIAS "joySetCapture" _
      (hWnd AS LONG, uJoyID AS LONG, uPeriod AS LONG, fChanged AS LONG) AS LONG


     DIM JoyInfoEx AS TJOYINFOEX
     DIM JoyX AS LONG, JoyY AS LONG

     JoySetCapture(Application.Handle, JOYSTICKID1, 1, 0)
     JoyReleaseCapture(JOYSTICKID1)

     JoyInfoEx.dwSize = 64
     JoyInfoEx.dwFlags = JOY_RETURNALL

     JoyGetPosEx(JOYSTICKID1, JoyInfoEx)

     JoyX = JoyInfoEx.dwXpos
     JoyY = JoyInfoEx.dwYpos

     PRINT "Move your joystick, and press some buttons, CTRL+C to break."
     DO
      JoyGetPosEx(JOYSTICKID1, JoyInfoEx)

      IF JoyInfoEx.dwXpos > JoyX+JOY_OFFSET THEN PRINT "RIGHT"
      IF JoyInfoEx.dwXpos < JoyX-JOY_OFFSET THEN PRINT "LEFT"
      IF JoyInfoEx.dwYpos > JoyY+JOY_OFFSET THEN PRINT "DOWN"
      IF JoyInfoEx.dwYpos < JoyY-JOY_OFFSET THEN PRINT "UP"
      IF JoyInfoEx.dwButtons > - THEN PRINT "Button "; JoyInfoEx.dwButtons; " pressed."
     LOOP
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Mon 2024-4-15  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2013-06-19 07:52:19