October 28, 2020, 04:56:53 AM

Author Topic: [bb] GetJoyProperty$() by fredborg [ 1+ years ago ]  (Read 1293 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] GetJoyProperty$() by fredborg [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
Title : GetJoyProperty$()
Author : fredborg
Posted : 1+ years ago

Description : Simply place the top stuff in a file called winmm.decls and place it in your userlibs folder!

Getting the joystick name may NOT work properly on WindowsXP!

Got a better way of doing it? <a href="http://www.blitzbasic.co.nz/Community/posts.php?topic=27703" target="_blank">Post it here![/url]


Code :
Code: BlitzBasic
  1. ; Winmm.decls
  2. ; Place in userlib folder and uncomment command
  3. ;
  4. ;.lib "winmm.dll"
  5. ;winmm_joyGetDevCaps%(id%,lpCaps*,uSize%):"joyGetDevCapsA"
  6.  
  7. ;
  8. ; Joystick Property constants
  9. ; Do not change!
  10. ;
  11. Const joy_Mid                   = 0
  12. Const joy_Pid                   = 2
  13. Const joy_Name                  = 4
  14. Const joy_Xmin                  = 36
  15. Const joy_Xmax                  = 40
  16. Const joy_Ymin                  = 44
  17. Const joy_Ymax                  = 48
  18. Const joy_Zmin                  = 52
  19. Const joy_Zmax                  = 56
  20. Const joy_NumButtons    = 60
  21. Const joy_PeriodMin             = 64
  22. Const joy_PeriodMax             = 68
  23. Const joy_Rmin                  = 72
  24. Const joy_Rmax                  = 76
  25. Const joy_Umin                  = 80
  26. Const joy_Umax                  = 84
  27. Const joy_Vmin                  = 88
  28. Const joy_Vmax                  = 92
  29. Const joy_Caps                  = 96
  30. Const joy_MaxAxes               = 100
  31. Const joy_NumAxes               = 104
  32. Const joy_MaxButtons    = 108
  33. Const joy_RegKey                = 112
  34. Const joy_OEMVxD                = 144
  35.  
  36. ;
  37. ; Use this function to get a joystick property
  38. ;
  39. Function GetJoyProperty$(port,property)
  40.  
  41.         joybank = CreateBank(1024)
  42.  
  43.         ret$ = ""
  44.         For i = 0 To 1023
  45.                 error = winmm_joyGetDevCaps(port,joybank,i)
  46.                 If error = 0
  47.                         If (property = joy_Mid) Or (property = joy_Pid)
  48.                                 ret$ = PeekShort(joybank,property)                     
  49.                         ElseIf (property = joy_Name) Or (property = joy_RegKey) Or (property = joy_OEMVxD)
  50.                                 For j = property To BankSize(joybank)-1
  51.                                         ch = PeekByte(joybank,j)
  52.                                         If ch = 0 Then Exit
  53.                                         ret$ = ret$+Chr$(ch)
  54.                                 Next
  55.                         Else
  56.                                 ret$ = PeekInt(joybank,property)
  57.                         End If
  58.                         Exit
  59.                 End If
  60.         Next
  61.        
  62.         FreeBank joybank
  63.        
  64.         If error <> 0
  65.                 Return "Joystick "+port+" Not Found!"
  66.         Else
  67.                 Return ret$
  68.         End If
  69.        
  70. End Function
  71.  
  72. ;
  73. ; (Really useless) example
  74. ;
  75.  
  76. Graphics 400,400,0,2
  77.  
  78. joyport = 0
  79. Print "Joystick "+joyport+" Properties:"
  80. Print "  Mid        - "+GetJoyProperty(joyport,joy_Mid)
  81. Print "  Pid        - "+GetJoyProperty(joyport,joy_Pid)
  82. Print "  Name       - "+GetJoyProperty(joyport,joy_Name)
  83. Print "  Xmin       - "+GetJoyProperty(joyport,joy_Xmin)
  84. Print "  Xmax       - "+GetJoyProperty(joyport,joy_Xmax)
  85. Print "  Ymin       - "+GetJoyProperty(joyport,joy_Ymin)
  86. Print "  Ymax       - "+GetJoyProperty(joyport,joy_Ymax)
  87. Print "  Zmin       - "+GetJoyProperty(joyport,joy_Zmin)
  88. Print "  Zmax       - "+GetJoyProperty(joyport,joy_Zmax)
  89. Print "  NumButtons - "+GetJoyProperty(joyport,joy_NumButtons)
  90. Print "  PeriodMin  - "+GetJoyProperty(joyport,joy_PeriodMin)
  91. Print "  PeriodMax  - "+GetJoyProperty(joyport,joy_PeriodMax)
  92. Print "  Rmin       - "+GetJoyProperty(joyport,joy_Rmin)
  93. Print "  Rmax       - "+GetJoyProperty(joyport,joy_Rmax)
  94. Print "  Umin       - "+GetJoyProperty(joyport,joy_Umin)
  95. Print "  Umax       - "+GetJoyProperty(joyport,joy_Umax)
  96. Print "  Vmin       - "+GetJoyProperty(joyport,joy_Vmin)
  97. Print "  Vmax       - "+GetJoyProperty(joyport,joy_Vmax)
  98. Print "  Caps       - "+GetJoyProperty(joyport,joy_Caps)
  99. Print "  MaxAxes    - "+GetJoyProperty(joyport,joy_MaxAxes)
  100. Print "  NumAxes    - "+GetJoyProperty(joyport,joy_NumAxes)
  101. Print "  MaxButtons - "+GetJoyProperty(joyport,joy_MaxButtons)
  102. Print "  RegKey     - "+GetJoyProperty(joyport,joy_RegKey)
  103. Print "  OEMVxD     - "+GetJoyProperty(joyport,joy_OEMVxD)
  104. Print
  105. Print "Press any key to quit!"
  106. WaitKey()
  107. End


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal