Hab gerade ein paar Joystickfunktionen programmiert, mit denen man
den Status des Joystick genauer abfragen kann als mit JoystickAxisX() bzw. JoystickAxisY().

Code: Alles auswählen
Structure DIJOYSTATE
lX.l
lY.l
lZ.l
lRx.l
lRy.l
lRz.l
rglSlider.l[2]
rgdwPOV.l[4]
rgbButtons.b[32]
EndStructure
Structure DIDEVICEINSTANCE
dwSize.l
guidInstance.guid
guidProduct.guid
dwDevType.l
tszInstanceName.b[#MAX_PATH]
tszProductName.b[#MAX_PATH]
guidFFDriver.guid
wUsagePage.w
wUsage.w
EndStructure
Structure DIDEVCAPS
dwSize.l
dwFlags.l
dwDevType.l
dwAxes.l
dwButtons.l
dwPOVs.l
dwFFSamplePeriod.l
dwFFMinTimeResolution.l
dwFirmwareRevision.l
dwHardwareRevision.l
dwFFDriverVersion.l
EndStructure
Procedure GetJoystickDevice()
!extrn _PB_Joystick_Current
!MOV Eax,[_PB_Joystick_Current]
ProcedureReturn
EndProcedure
Procedure JoystickX();returns a number from -1000 to 1000
*Joystick.IDirectInputDevice7A=GetJoystickDevice()
*Joystick\GetDeviceState(SizeOf(DIJOYSTATE),State.DIJOYSTATE)
ProcedureReturn State\lX
EndProcedure
Procedure JoystickY();returns a number from -1000 to 1000
*Joystick.IDirectInputDevice7A=GetJoystickDevice()
*Joystick\GetDeviceState(SizeOf(DIJOYSTATE),State.DIJOYSTATE)
ProcedureReturn State\lY
EndProcedure
Procedure JoystickZ();returns a number from -1000 to 1000
*Joystick.IDirectInputDevice7A=GetJoystickDevice()
*Joystick\GetDeviceState(SizeOf(DIJOYSTATE),State.DIJOYSTATE)
ProcedureReturn State\lZ
EndProcedure
Procedure JoystickU();returns a number from -1000 to 1000
*Joystick.IDirectInputDevice7A=GetJoystickDevice()
*Joystick\GetDeviceState(SizeOf(DIJOYSTATE),State.DIJOYSTATE)
ProcedureReturn State\rglSlider[0]
EndProcedure
Procedure JoystickV();returns a number from -1000 to 1000
*Joystick.IDirectInputDevice7A=GetJoystickDevice()
*Joystick\GetDeviceState(SizeOf(DIJOYSTATE),State.DIJOYSTATE)
ProcedureReturn State\rglSlider[1]
EndProcedure
Procedure GetNumberOfButtons()
*Joystick.IDirectInputDevice7A=GetJoystickDevice()
Caps.DIDEVCAPS\dwSize=SizeOf(DIDEVCAPS)
*Joystick\GetCapabilities(Caps)
ProcedureReturn Caps\dwButtons
EndProcedure
Procedure GetNumberOfAxes()
*Joystick.IDirectInputDevice7A=GetJoystickDevice()
Caps.DIDEVCAPS\dwSize=SizeOf(DIDEVCAPS)
*Joystick\GetCapabilities(Caps)
ProcedureReturn Caps\dwAxes
EndProcedure
Procedure.s JoystickName()
*Joystick.IDirectInputDevice7A=GetJoystickDevice()
Info.DIDEVICEINSTANCE\dwSize=SizeOf(DIDEVICEINSTANCE)
*Joystick\GetDeviceInfo(Info)
ProcedureReturn PeekS(@Info\tszProductName[0])
EndProcedure
;Example:
If InitJoystick()=0 Or InitSprite()=0
MessageRequester("Error","Can't initialize DirectX 7.")
End
EndIf
flags=#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered
OpenWindow(1,0,0,250,250,flags,"enhanced Joystick-commands")
OpenWindowedScreen(WindowID(),0,0,250,250,0,0,0)
Repeat
ExamineJoystick()
ClearScreen(0,0,0)
StartDrawing(ScreenOutput())
LineXY(0,125,250,125,#white)
LineXY(125,0,125,250,#white)
Locate(0,0)
FrontColor(255,255,0)
BackColor(0,0,0)
DrawingFont(GetStockObject_(#ANSI_VAR_FONT))
DrawText(JoystickName())
Circle(JoystickX()/8+125,JoystickY()/8+125,10,#red)
StopDrawing()
FlipBuffers()
Until WindowEvent()=#PB_Event_CloseWindow
Stefan