05-18-2023, 08:36 PM
I added this to the top of the loop:
and your code seems to be working (full program below).
step 1: no game controller plugged in yet
Step 2: after plugging in a game controller
Step 3: after unplugging game controller
Step 4: after plugging the controller back in
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)
While _DeviceInput(1): Wend
and your code seems to be working (full program below).
step 1: no game controller plugged in yet
Step 2: after plugging in a game controller
Step 3: after unplugging game controller
Step 4: after plugging the controller back in
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