09-07-2025, 09:12 PM
Hi,
Here’s a small program to test the use of a gamepad; tested with only one gamepad, so it might have some bugs
Here’s a small program to test the use of a gamepad; tested with only one gamepad, so it might have some bugs
Code: (Select All)
$console
_dest _console
? "gamepad tester"
screenWidth% = 640
screenHeight% = 480
page0& = _newimage (screenWidth%,screenHeight%,32)
display& = _newimage (screenWidth%,screenHeight%,32)
screen display&
displayTextCenter page0&, screenWidth%/2, screenHeight%/2, _rgb(160,160,160), "YO"
_dest _console
for i% = 1 to _devices
dv$ = _device$(i%)
? dv$
? "buttons = ";_lastbutton(i%), "axis = ";_lastaxis(i%), "wheels = ";_lastwheel(i%)
if left$(dv$,12) = "[CONTROLLER]" then
controller% = i%
buttons% = _lastbutton(i%)
axis% = _lastaxis(i%)
end if
next i%
_dest 0
if controller% = 0 and buttons% = 0 and axis% = 0 then
cls
displayTextCenter _
display&, _
screenWidth%/2, screenHeight%/2 - 2 * _fontheight, _
_rgb(255,63,63), _
"No gamepad device found !"
displayTextCenter _
display&, _
screenWidth%/2, screenHeight%/2 + _fontheight, _
_rgb(255,63,63), _
"Connect a joystick then relaunch this program."
color _rgb(127,127,127)
end
end if
fps% = 60
clstep% = 255 \ fps%
bfm% = 4 * buttons% - 1
axm% = axis% \ 2
xl% = (screenWidth% - 30 * (bfm% \ 4 + 1)) \ 2
redim bf%(0 to bfm%)
do
_limit fps%
_dest page0&
color _rgb(0,0,0),_rgb(0,0,0)
cls
displayTextAlignLeft _
page0&, _
10, screenHeight% - _fontheight, _
_rgb(160,160,160), _
"Quit: press Escape"
displayTextAlignLeft _
page0&, _
10, 10, _
_rgb(160,160,160), _
"device #"+_tostr$(controller%)+" : "+_tostr$(buttons%)+" buttons, "+_tostr$(axis%)+" axis."
displayTextAlignLeft page0&, 10, 130, _rgb(127,127,127), "strig(??,1)"
for i%=0 to bfm%
p% = strig(i%,1)
if p% then
bf%(i%) = fps%
c& = _rgb(255,0,0)
else
if bf%(i%) = 0 then
c& = _rgb(63,63,63)
elseif bf%(i%) > 0 then
bf%(i%) = bf%(i%) - 1
c& = _rgb(clstep% * bf%(i%),clstep% * bf%(i%),0)
end if
end if
t$ = str$(i%)
displayTextAlignRight page0&, xl% + 50 + 30 * (i% \ 4), 100 + 30 * (i% mod 4), c&, t$
next i%
for i% = 1 to axm%
px% = stick(0,i%)
y% = 200 + 2.5 * _fontheight * i%
displayTextAlignLeft page0&, 10, y%, _rgb(127,127,127), "stick(0,"+_tostr$(i%)+")"
displayTextCenter page0&, 100 + 2 * px%, y%, _rgb(63,255,63), " "+_tostr$(px%)+" "
py% = stick(1,i%)
y% = y% + 1.25 * _fontheight
displayTextAlignLeft page0&, 10, y%, _rgb(127,127,127), "stick(1,"+_tostr$(i%)+")"
displayTextCenter page0&, 100 + 2 * py%, y%, _rgb(63,255,63), " "+_tostr$(py%)+" "
next i%
_dest 0
_putimage , page0&, 0
if inkey$ = chr$(27) then system
loop
sub displayTextCenter(d&,x%,y%,c&,t$)
_dest d&
color c&, _rgba(0,0,0,0)
_printstring(x% - _printwidth(t$,d&)/ 2,y%),t$
end sub
sub displayTextAlignLeft(d&,x%,y%,c&,t$)
_dest d&
color c&, _rgba(0,0,0,0)
_printstring(x%,y%),t$
end sub
sub displayTextAlignRight(d&,x%,y%,c&,t$)
_dest d&
color c&, _rgba(0,0,0,0)
_printstring(x% - _printwidth(t$,d&),y% - _fontheight),t$
end sub
