07-23-2024, 10:40 PM
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? Thanks.
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? 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 '