QB64 Phoenix Edition v3.7.0 Released!
#43
(05-08-2023, 02:53 PM)TerryRitchie Wrote: I'm having no issues with the updates to _DEVICES and related commands. Here is a test snippet of code that I wrote. It detects when new controllers have been added and when they have been disconnected.

Code: (Select All)
DIM Devices AS INTEGER
DIM Fcount AS INTEGER
DIM d AS INTEGER
DIM DeviceName AS STRING

Devices = _DEVICES
Fcount = 0

DO
    CLS
    _LIMIT 30
    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

Hi Terry
thank you for the time spent to solve my issue and the code posted here!
I agree with you that your code manages very well the state of connected or disconneted of the joystick.
It solves half of the problem, but it is so much and moreover you have now teached me that the state of CONNECTED/DISCONNECTED lasts in the description of the device detected.
The other half of the problem is to be able to change type of joystick on the same USB or/and  to change the USB to which the same Joystick has been connected.
Why these two limit cases? I do not think that they are weird, because in different knid of game there is the SETUP/OPTIONS section in which you can detect and choose the input controller and also map/define the action of the buttons of the controller. That is the final goal of this my tedious query.
Again thank you very much for your feedback.

Long life to the king QB64pe!  I love QB64pe and its community.
Reply


Messages In This Thread
RE: QB64 Phoenix Edition v3.7.0 Released! - by TempodiBasic - 05-09-2023, 07:59 PM



Users browsing this thread: 29 Guest(s)