Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HELP! I find an issue using _DEVICES!
#1
Hi QB64 coders

I was attempting to accomplish this task
detecting a joystick and its settings of  buttons/axis

using the original code I thought that I made an error in typing code. So with the goal to solve this issue of detecting a Joystick before to change its settings of _BUTTONS, I fall in this issue that you can live running this code and following these instructions:
1.  copy and paste this code into QB64 IDE
2.  take near you an USB joystick
3.  press F5 after QB64 IDE with this demo code has got the focus
4. you should get message "NO Joystick! 2   0   0    0"
5. pressing ENTER key you should get the same message on the screen
6. Plug in the USB joystick to the PC/Notebook and wait for the sound of controller connected by Windows 11
7. press 3 times ENTER Key, you should get a message "Joystick detected  3 .........." three times
8. disconnect the USB joystick and wait for the sound of controller disconnected by Windows 11
9. press ENTER key and WHAT message do you get back?

Here the code that I used

Code: (Select All)
 
ReDim Shared Ax(1 To 1) As Integer, Bx(1 To 1) As Integer, Wx(1 To 1) As Integer
ReDim Shared Axm As Integer, Bxm As Integer, Wxm As Integer
Dim Kh As Integer

Cls
Print " Press ESC to quit and Enter to detect joystick"
Print " JoyStick  Axis        Buttons      Wheels"
Print IsJoystick%, Axm, Bxm, Wxm
View Print 4 To 24
Kh = 0
While Kh <> 27
    Kh = _KeyHit
    If (Kh) = 13 Then Print IsJoystick%, Axm, Bxm, Wxm
    Locate 24, 1: Print Kh;
    _Limit 30
Wend
End

'*****************************************************************
'            JOYSTICK DETECTION
'*****************************************************************
Function IsJoystick% ()
    Dim HMD%: HMD% = HowManyDevice%

    If HMD% = 0 Then
        Print " No input devices!": End
    Else
        Locate , 1: Print HMD%
    End If

    If HMD% = 3 Then
        Locate , 4: Print "Joystick detected";
        IsJoystick% = -1
        Axm = _LastAxis(3)
        Bxm = _LastButton(3)
        Wxm = _LastWheel(3)
    Else
        ' all cases in which HMD% <>3
        Locate , 10: Print " NO Joystick!";
        IsJoystick% = 0
        Axm = 0
        Bxm = 0
        Wxm = 0
    End If
    Print HMD%, Axm, Bxm, Wxm
End Function

Function HowManyDevice%
    HowManyDevice% = 0 ' error value
    HowManyDevice% = _Devices ' value detected
End Function
'*****************************************************************
'        END Subs and Functions for JOYSTICK DETECTION
'*****************************************************************

Here my weird output


[Image: immagine-2023-05-02-004435348.png]

detection is stuck!

So please make bigger my knowledge with your feedbacks!
Where is the mistake in the code?
Thank you for your apport!
Reply


Messages In This Thread
HELP! I find an issue using _DEVICES! - by TempodiBasic - 05-01-2023, 10:58 PM



Users browsing this thread: 7 Guest(s)