This code does not check if you have a joystick installed and automatically assumes your game controller is using JOYSTICKID1.
Code: Select all
Import "Winmm.lib"
joyGetPos(uJoyID.i, pji.l)As"_joyGetPos@8"
EndImport
;IncludeFile "WinAPI.pbi"
#JOYSTICK_DEFAULT_VALUE = 32767 ; values 32767 come from debugging pji\wXpos and pji\wYpos, change this to whatever your joystick defaults to
Structure jinfo : wXpos.i : wYpos.i : wZpos.i : wButtons.i : EndStructure
Structure cpoint : x.l : y.l : EndStructure
pji.jinfo
cp.cpoint
OpenWindow(#PB_Any, 0, 0, 200, 200, "Gamepad joystick thingy", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
Repeat : eventID = WaitWindowEvent(1)
Delay(1)
joyGetPos(#JOYSTICKID1,pji)
; -- Octo-directional joystick movement, too dumb to do any math :(
If pji\wXpos > #JOYSTICK_DEFAULT_VALUE : xBit = 1 : ElseIf pji\wXpos < #JOYSTICK_DEFAULT_VALUE : xBit = -1 : Else : xBit = 0 : EndIf
If pji\wYpos > #JOYSTICK_DEFAULT_VALUE : yBit = 1 : ElseIf pji\wYpos < #JOYSTICK_DEFAULT_VALUE : yBit = -1 : Else : yBit = 0 : EndIf
GetCursorPos_(cp)
SetCursorPos_(cp\x+xBit, cp\y+yBit)
Until eventID = #PB_Event_CloseWindow