Author Topic: How Read all Joysticks and Buttons of Logitech F310 Gamepad (as XBox)  (Read 1185 times)

0 Members and 1 Guest are viewing this topic.

Offline acjacques

  • Newbie
  • Posts: 33
I have finished a code to read all functions of a Logitech F310 gamepad.
Then I am sharing the code:
Code: QB64: [Select]
  1.  'This code read all functions of a Logitech F310 gamepad. The back switch is on X position.
  2. 'Writed by ACJacques     acj@infolink.com.br    June/2020
  3.     FUNCTION joyGetPosEx& (BYVAL uJoyID AS _UNSIGNED INTEGER, joyref AS LONG)
  4.  
  5. TYPE JOYINFOEX
  6.     dwSize AS LONG
  7.     dwFlags AS LONG
  8.     dwXpos AS LONG
  9.     dwYpos AS LONG
  10.     dwZpos AS LONG
  11.     dwRpos AS LONG
  12.     dwUpos AS LONG
  13.     dwVpos AS LONG
  14.     dwButtons AS LONG
  15.     dwButtonNumber AS LONG
  16.     dwPOV AS LONG
  17.     dwReserved1 AS LONG
  18.     dwReserved2 AS LONG
  19.  
  20. DIM Joy1 AS JOYINFOEX
  21. Joy1.dwSize = LEN(Joy1)
  22.  
  23.     x& = joyGetPosEx(0, Joy1.dwSize) 'using Windows DLL to get better resolution
  24.  
  25.     LOCATE 1, 1:
  26.  
  27.     PRINT USING "####"; (Joy1.dwXpos / 64) 'j esquerdo h    left joystick horizontal       all converted to 10 bits     1024
  28.     PRINT USING "####"; (Joy1.dwYpos / 64) 'j esquerdo v    left joystick vertical
  29.     PRINT USING "####"; (Joy1.dwUpos / 64) 'j direto h      right joystick horizontal
  30.     PRINT USING "####"; (Joy1.dwRpos / 64) 'j direito v     right joystick vertical
  31.     PRINT USING "####"; (Joy1.dwZpos / 64) 'lt  rt
  32.     PRINT STRIG(1) 'botao A                       'using native  QB64  to get buttons
  33.     PRINT STRIG(5) 'botao B
  34.     PRINT STRIG(9) 'botao X
  35.     PRINT STRIG(13) 'botao Y
  36.     PRINT STRIG(17) 'botao lb
  37.     PRINT STRIG(21) 'botao rb
  38.     PRINT STRIG(25) 'botao back
  39.     PRINT STRIG(29) 'botao start
  40.     PRINT USING "###"; STICK(1, 3) ' Switches  Horizontal
  41.     PRINT USING "###"; STICK(0, 4) ' Switches  Vertical
  42.  
  43.  

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
You can also use _DEVICES for this, without needing the DECLARE LIBRARY code.  http://www.qb64.org/wiki/DEVICES



https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!