Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clearing _DEVICES
#2
I added this to the top of the loop: 

Code: (Select All)
While _DeviceInput(1): Wend

and your code seems to be working (full program below). 

step 1: no game controller plugged in yet
[Image: clearing-devices-01.png]

Step 2: after plugging in a game controller
[Image: clearing-devices-02.png]

Step 3: after unplugging game controller
[Image: clearing-devices-03.png]

Step 4: after plugging the controller back in
[Image: clearing-devices-04.png]

I only tried it on one computer so far (old MS Surface Pro 3 w/Windows 10) so if it's still not working for you, maybe try it on a different machine? 

Code: (Select All)
' Clearing _DEVICES
' https://qb64phoenix.com/forum/showthread.php?tid=1685

' TerryRitchie, 8-bit Enthusiast
' 05-14-2023, 01:12 AM
' Is there a way to force controller _DEVICES to be cleared and re-detected?
' For instance, when _DEVICES is first used in a running program the detected
' number of controllers will be returned. If one or more of the detected
' controllers is then disconnected the _DEVICE$ for the disconnected
' controllers will add "[DISCONNECTED]" to the string returned but still
' occupy a place in _DEVICES. If a user were to start plugging in random
' controllers after program startup the _DEVICES value will just keep
' growing with each new unique controller connected. The program listed
' below will show this in action. I would like to clear the _DEVICES list
' when a controller is listed as "[DISCONNECTED]" so _DEVICES can recount
' the actual number of controllers still plugged in if this is possible
' while a program is running. Any thoughts?

Dim Devices As Integer
Dim Fcount As Integer
Dim d As Integer
Dim DeviceName As String

Devices = _Devices
Fcount = 0

Do
    Cls
    _Limit 30
    While _DeviceInput(1): Wend ' <----- I ADDED THIS LINE TO REFRESH

    Fcount = Fcount + 1
    If Fcount = 30 Then '                                        check for new devices once per second
        Fcount = 1
        If _Devices <> Devices Then Devices = _Devices '         if number of devices changes get new count
    End If
    Print
    For d = 1 To Devices '                                       print found devices
        Color 14, 1
        DeviceName = _Device$(d)
        If InStr(DeviceName, "[DISCONNECTED]") Then Color 7, 0 ' change color if disconnected
        Print " Found: "; _Device$(d)
        Color 7, 0
    Next d
    _Display
Loop Until _KeyDown(27) '                                        press ESC to exit
Reply


Messages In This Thread
Clearing _DEVICES - by TerryRitchie - 05-14-2023, 05:12 AM
RE: Clearing _DEVICES - by madscijr - 05-18-2023, 08:36 PM
RE: Clearing _DEVICES - by TerryRitchie - 05-19-2023, 12:31 AM
RE: Clearing _DEVICES - by Ultraman - 05-19-2023, 11:03 AM
RE: Clearing _DEVICES - by TerryRitchie - 05-19-2023, 02:51 PM
RE: Clearing _DEVICES - by TempodiBasic - 05-24-2023, 07:36 AM
RE: Clearing _DEVICES - by Ultraman - 05-24-2023, 12:01 PM
RE: Clearing _DEVICES - by TempodiBasic - 05-25-2023, 02:47 PM



Users browsing this thread: 2 Guest(s)