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


Messages In This Thread
Joysticks on a Mac, _DEVICEINPUT() - by NakedApe - 07-23-2024, 10:40 PM
RE: Joysticks on a Mac, _DEVICEINPUT() - by a740g - 07-24-2024, 11:31 AM
RE: Joysticks on a Mac, _DEVICEINPUT() - by a740g - 07-28-2024, 09:33 AM
RE: Joysticks on a Mac, _DEVICEINPUT() - by Herve - 10-05-2025, 12:28 PM
RE: Joysticks on a Mac, _DEVICEINPUT() - by a740g - 10-22-2025, 01:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Mac print #file crlf? BlameTroi 5 329 02-16-2026, 08:42 PM
Last Post: BlameTroi
  Mac debugger not connecting, a user error! BlameTroi 0 99 02-07-2026, 06:18 PM
Last Post: BlameTroi
  Mac current release sigabrt BlameTroi 3 219 02-05-2026, 02:26 PM
Last Post: a740g
  QB64pe 4.0 on Mac Troubles NakedApe 14 2,239 12-29-2024, 01:53 AM
Last Post: NakedApe
  Compiling for Mac-OS mdijkens 12 2,464 03-13-2024, 10:24 PM
Last Post: NakedApe

Forum Jump:


Users browsing this thread: 1 Guest(s)