gamepad tester - Herve - 09-07-2025
Hi,
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
RE: gamepad tester - Herve - 09-09-2025
Hi,
New version that looks like this; it has been tested with a Sony DualSense controller; I welcome any feedback from tests with other controllers.
![[Image: gamepad-Tester.png]](https://i.ibb.co/vWYG3kQ/gamepad-Tester.png)
Code: (Select All)
type axis_amplitude_type
min as integer
max as integer
amplitude as integer
end type
$console
_dest _console
? "gamepad tester"
screenWidth% = 640
screenHeight% = 480
page0& = _newimage (screenWidth%,screenHeight%,32)
display& = _newimage (screenWidth%,screenHeight%,32)
screen display&
displayTextCenter _
display&, _
screenWidth%/2, screenHeight%/2 - _fontheight, _
_rgb(160,160,160), _
"GAMEPAD TESTER"
_delay 1
displayTextCenter _
display&, _
screenWidth%/2, screenHeight%/2 + _fontheight * 3, _
_rgb(160,160,160), _
"Ready !"
_delay 1
displayTextCenter _
display&, _
screenWidth%/2, screenHeight%/2 + _fontheight * 5, _
_rgb(160,160,160), _
"Plug your gamepad..."
_delay 1
displayTextCenter _
display&, _
screenWidth%/2, screenHeight%/2 + _fontheight * 7, _
_rgb(160,160,160), _
"Then press your keyboard to launch "
do until inkey$ > chr$(0) : _limit 60 : loop
_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
lastPressedButton% = -1
lastUsedAxis% = -1
fps% = 60
clstep% = 255 \ fps%
bfm% = 4 * buttons% - 1
axm% = axis% \ 2
xl% = (screenWidth% - 30 * (bfm% \ 4 + 1)) \ 2
redim bf%(0 to bfm%)
redim ax(1 to axis%) as axis_amplitude_type
resetAxisAmplitude ax()
do
_limit fps%
_dest page0&
color _rgb(0,0,0),_rgb(0,0,0)
cls
if lastUsedAxis% > -1 then
msg$ = "last pressed button : " + _tostr$(lastPressedButton%)
else
msg$ = "last pressed button : none"
end if
displayTextAlignLeft _
page0&, _
10, 30, _
_rgb(160,160,160), _
"last pressed button : " + _tostr$(lastPressedButton%)
if lastUsedAxis% > 0 then
msg$ = "max amplitude used axis : " + _tostr$(lastUsedAxis%) + " (press keyboard to reset)"
else
msg$ = "max amplitude used axis : move axis needed"
end if
displayTextAlignLeft _
page0&, _
10, 50, _
_rgb(160,160,160), _
msg$
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)
lastPressedButton% = i% \ 4 + 1
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%
for d% = 0 to 1
px% = stick(d%,i%)
y% = 200 + 2.5 * _fontheight * i%
axi% = 2*(i% -1) + d% + 1
if px% < ax(axi%).min then ax(axi%).min = px%
if px% > ax(axi%).max then ax(axi%).max = px%
displayTextAlignLeft _
page0&, _
10, y% + d% * 1.25 * _fontheight, _
_rgb(127,127,127), _
"stick("+_tostr$(d%)+","+_tostr$(i%)+")"
displayTextCenter _
page0&, _
110 + 2 * px%, y% + d% * 1.25 * _fontheight, _
_rgb(63,255,63), _
right$("00"+_tostr$(px%),3) '+"("+_tostr$(ax(axi%).amplitude)+"):"+_tostr$(axi%)
displayTextAlignLeft _
page0&, _
110 + 2 * ax(axi%).min - 2.5 * _fontwidth, y% + d% * 1.25 * _fontheight, _
_rgba(0,255,0,128), _
"["
displayTextAlignRight _
page0&, _
110 + 2 * ax(axi%).max + 2.5 * _fontwidth, y% + d% * 1.25 * _fontheight, _
_rgba(0,255,0,128), _
"]"
next d%
next i%
max% = 20
for i% = lbound(ax) to ubound(ax)
ax(i%).amplitude = ax(i%).max - ax(i%).min
if ax(i%).amplitude > max% then
lastUsedAxis% = i%
max% = ax(i%).amplitude
end if
next i%
_dest 0
_putimage , page0&, 0
if inkey$ = chr$(27) then system
if _keyhit then
resetAxisAmplitude ax()
lastUsedAxis% = -1
end if
loop
sub resetAxisAmplitude(aa() as axis_amplitude_type)
for i% = lbound(aa) to ubound(aa)
aa(i%).min = 255
aa(i%).max = 0
next i%
end sub
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%),t$
end sub
RE: gamepad tester - Unseen Machine - 09-09-2025
Looks good to me, ill be sure to test my xbox 360 controller with it in the next couple of days and report back...
Code: (Select All)
sub resetAxisAmplitude(aa() as axis_amplitude_type)
for i% = lbound(aa) to ubound(aa)
aa(i%).min = 255
aa(i%).max = 0
next i%
end sub
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%),t$
end sub
These should all be in one sub in my head, an Allignment flag dictating left middle or right, it'll save the select cases youve got handling it too...other wise...nice work!
John
RE: gamepad tester - SMcNeill - 09-10-2025
(09-09-2025, 10:28 PM)Unseen Machine Wrote: Looks good to me, ill be sure to test my xbox 360 controller with it in the next couple of days and report back...
John
Give this a test run as well and test it: https://qb64phoenix.com/forum/showthread.php?tid=3424
Seems not a ton of folks have joysticks, so it's hard to get testing and feedback on anything involving them sometimes.
RE: gamepad tester - Herve - 09-10-2025
(09-09-2025, 10:28 PM)Unseen Machine Wrote: These should all be in one sub in my head, an Allignment flag dictating left middle or right, it'll save the select cases youve got handling it too...other wise...nice work! Oh, good advice—it's done!
Code: (Select All)
type axis_amplitude_type
min as integer
max as integer
amplitude as integer
end type
const ALIGN_LEFT = -1
const ALIGN_CENTER = 0
const ALIGN_RIGHT = 1
$console
_dest _console
? "gamepad tester"
screenWidth% = 640
screenHeight% = 480
page0& = _newimage (screenWidth%,screenHeight%,32)
display& = _newimage (screenWidth%,screenHeight%,32)
screen display&
displayText _
display&, _
screenWidth%/2, screenHeight%/2 - _fontheight, _
_rgb(160,160,160), _
"GAMEPAD TESTER", _
ALIGN_CENTER
_delay 1
displayText _
display&, _
screenWidth%/2, screenHeight%/2 + _fontheight * 3, _
_rgb(160,160,160), _
"Ready !", _
ALIGN_CENTER
_delay 1
displayText _
display&, _
screenWidth%/2, screenHeight%/2 + _fontheight * 5, _
_rgb(160,160,160), _
"Plug your gamepad...", _
ALIGN_CENTER
_delay 1
displayText _
display&, _
screenWidth%/2, screenHeight%/2 + _fontheight * 7, _
_rgb(160,160,160), _
"Then press your keyboard to launch ", _
ALIGN_CENTER
do until inkey$ > chr$(0) : _limit 60 : loop
_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
displayText _
display&, _
screenWidth%/2, screenHeight%/2 - 2 * _fontheight, _
_rgb(255,63,63), _
"No gamepad device found !", _
ALIGN_CENTER
displayText _
display&, _
screenWidth%/2, screenHeight%/2 + _fontheight, _
_rgb(255,63,63), _
"Connect a joystick then relaunch this program.", _
ALIGN_CENTER
color _rgb(127,127,127)
end
end if
lastPressedButton% = -1
lastUsedAxis% = -1
fps% = 60
clstep% = 255 \ fps%
bfm% = 4 * buttons% - 1
axm% = axis% \ 2
xl% = (screenWidth% - 30 * (bfm% \ 4 + 1)) \ 2
redim bf%(0 to bfm%)
redim ax(1 to axis%) as axis_amplitude_type
resetAxisAmplitude ax()
do
_limit fps%
_dest page0&
color _rgb(0,0,0),_rgb(0,0,0)
cls
if lastUsedAxis% > -1 then
msg$ = "last pressed button : " + _tostr$(lastPressedButton%)
else
msg$ = "last pressed button : none"
end if
displayText _
page0&, _
10, 30, _
_rgb(160,160,160), _
"last pressed button : " + _tostr$(lastPressedButton%), _
ALIGN_LEFT
if lastUsedAxis% > 0 then
msg$ = "max amplitude used axis : " + _tostr$(lastUsedAxis%) + " (press keyboard to reset)"
else
msg$ = "max amplitude used axis : move axis needed"
end if
displayText _
page0&, _
10, 50, _
_rgb(160,160,160), _
msg$, _
ALIGN_LEFT
displayText _
page0&, _
10, screenHeight% - _fontheight, _
_rgb(160,160,160), _
"Quit: press Escape", _
ALIGN_LEFT
displayText _
page0&, _
10, 10, _
_rgb(160,160,160), _
"device #"+_tostr$(controller%)+" : "+_tostr$(buttons%)+" buttons, "+_tostr$(axis%)+" axis.", _
ALIGN_LEFT
displayText _
page0&, _
10, 130, _
_rgb(127,127,127), _
"strig(??,1)", _
ALIGN_LEFT
for i%=0 to bfm%
p% = strig(i%,1)
if p% then
bf%(i%) = fps%
c& = _rgb(255,0,0)
lastPressedButton% = i% \ 4 + 1
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%)
displayText _
page0&, _
xl% + 50 + 30 * (i% \ 4), 100 + 30 * (i% mod 4), _
c&, _
t$, _
ALIGN_RIGHT
next i%
for i% = 1 to axm%
for d% = 0 to 1
px% = stick(d%,i%)
y% = 200 + 2.5 * _fontheight * i%
axi% = 2*(i% -1) + d% + 1
if px% < ax(axi%).min then ax(axi%).min = px%
if px% > ax(axi%).max then ax(axi%).max = px%
displayText _
page0&, _
10, y% + d% * 1.25 * _fontheight, _
_rgb(127,127,127), _
"stick("+_tostr$(d%)+","+_tostr$(i%)+")", _
ALIGN_LEFT
displayText _
page0&, _
110 + 2 * px%, y% + d% * 1.25 * _fontheight, _
_rgb(63,255,63), _
right$("00"+_tostr$(px%),3), _
ALIGN_CENTER
displayText _
page0&, _
110 + 2 * ax(axi%).min - 2.5 * _fontwidth, y% + d% * 1.25 * _fontheight, _
_rgba(0,255,0,128), _
"[", _
ALIGN_LEFT
displayText _
page0&, _
110 + 2 * ax(axi%).max + 2.5 * _fontwidth, y% + d% * 1.25 * _fontheight, _
_rgba(0,255,0,128), _
"]", _
ALIGN_RIGHT
next d%
next i%
max% = 20
for i% = lbound(ax) to ubound(ax)
ax(i%).amplitude = ax(i%).max - ax(i%).min
if ax(i%).amplitude > max% then
lastUsedAxis% = i%
max% = ax(i%).amplitude
end if
next i%
_dest 0
_putimage , page0&, 0
if inkey$ = chr$(27) then system
if _keyhit then
resetAxisAmplitude ax()
lastUsedAxis% = -1
end if
loop
sub resetAxisAmplitude(aa() as axis_amplitude_type)
for i% = lbound(aa) to ubound(aa)
aa(i%).min = 255
aa(i%).max = 0
next i%
end sub
sub displayText(d&,x%,y%,c&,t$,a%)
_dest d&
color c&, _rgba(0,0,0,0)
select case a%
case ALIGN_CENTER
_printstring(x% - _printwidth(t$,d&)/ 2,y%),t$
case ALIGN_RIGHT
_printstring(x% - _printwidth(t$,d&),y%),t$
case else
_printstring(x%,y%),t$
end select
end sub
|