Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Joysticks on a Mac, _DEVICEINPUT()
#1
Does anybody know if _DEVICE$ and _DEVICEINPUT() work on MacOS? I was just noodling around with a cheap joystick I got, but any reference to _DEVICEINPUT(3) causes an Illegal Function error. Also the stick doesn't show up as connected under _DEVICE$. I was using a few of Terry's (@TerryRitchie) joystick and device demo programs to get started.

This mashup below sorta works - it gets some input from the stick, but only when the stick is moved from the zero, zero position - when action is detected generically. Without using _DEVICEINPUT(3) I can't get actual live input. What's a guy to do?   Dodgy  Thanks.


Code: (Select All)
CONST JOYSTICK = 3 '        joystick controller id (may need to change to match your joystick id)

DIM DeviceCount AS INTEGER ' number of controller devices (used to activate)
DIM Threshold AS SINGLE '    amount of deflection needed to activate movement
DIM Xaxis AS SINGLE '        value of joystick x axis (horizontal)
DIM Yaxis AS SINGLE '        value of joystick y axis (vertical)
DIM x AS SINGLE '            x location of circle
DIM y AS SINGLE '            y location of circle
DIM Speed AS INTEGER '      axis speed multiplier

DeviceCount = _DEVICES '                                        activate controller statements
Threshold = .05 '                                              set axis threshold
Speed = 10 '                                                    set axis speed multiplier
x = 319 '                                                      center circle
y = 239
SCREEN _NEWIMAGE(640, 480, 32) '                                graphics screen
DO '                                                            begin controller loop
    _LIMIT 60 '                                                  60 frames per second
    CLS '                                                        clear screen
    LOCATE 2, 16 '                                              position cursor
    PRINT "Use joystick handle to move circle. Esc to exit." '  display instructions

    DeviceInput = _DEVICEINPUT '                                get any controller interaction
    IF DeviceInput THEN '                                        was a controller interacted with?
        WHILE _DEVICEINPUT(DeviceInput): WEND '                  yes, get the latest controller information

        'WHILE _DEVICEINPUT(JOYSTICK): WEND '      THIS CAUSES INSTANT CRASH  reference joystick 1 and get latest update
        Xaxis = _AXIS(1) '                                          get current horizontal value
        Yaxis = _AXIS(2) '                                          get current vertical value
        IF ABS(Xaxis) >= Threshold THEN x = x + Xaxis * Speed '      move circle horizontally if threshold met
        IF ABS(Yaxis) >= Threshold THEN y = y + Yaxis * Speed '      move circle vertically if threshold met
        IF x < 0 THEN x = x + 639 ELSE IF x > 639 THEN x = x - 639 ' keep horizontal movement on screen
        IF y < 0 THEN y = y + 479 ELSE IF y > 479 THEN y = y - 479 ' keep vertical movement on screen
        CIRCLE (x, y), 30 '                                          draw the circle
        _DISPLAY '                                                  update screen with changes
    END IF
LOOP UNTIL _KEYDOWN(27) '                                      leave when ESC pressed
SYSTEM '
Reply
#2
I'll can test with an XBox 360 controller during the weekend. Will let you know.
Reply
#3
Thanks, a740g!
Reply
#4
Quick update:

So, it seems that macOS does not support a wired Xbox 360 controller. Also, the PS4 and the Xbox One controllers are supported only when connected via BT.  Sad

https://support.apple.com/en-us/111099

I am still trying to figure out how to get my wired Xbox 360 controller to work.

There is this: https://github.com/360Controller/360Controller

But it has not been updated in ages and there is no support for Big Sur and above.
Reply
#5
Thanks, sounds like I need a PC for this assignment. Appreciate you taking a look!
Reply




Users browsing this thread: 1 Guest(s)