这篇笔记我整理了好久也没法整理清楚,不过其中一部分要感谢XiaoY_H的文章:
游戏手柄编程DEMO 基于 VB.NET+API 暂无力反馈
它的代码帮了我大忙,十分感谢!
核心:手柄信号采样类申明及实现
Public Class PlayJoyControl
Public Const JOY_RETURNBUTTONS = &H80&
Public Structure JOYINFOEX
Dim dwSize As Integer 'size of structure
Dim dwFlags As Integer ' flags to indicate what to return
Dim wXpos As Integer ' x position
Dim wYpos As Integer ' y position
Dim wZpos As Integer ' z position
Dim wRpos As Integer ' rudder/4th axis position
Dim wUpos As Integer ' 5th axis position
Dim wVpos As Integer ' 6th axis position
Dim wButtons As Integer ' button states
Dim wButtonNumber As Integer ' current button number pressed
Dim dwPOV As Integer ' point of view state
Dim dwReserved1 As Integer ' reserved for communication between winmm driver
Dim dwReserved2 As Integer ' reserved for future expansion
Dim DeviceState As String
End Structure
Private Declare Function joyGetPosEx Lib "winmm.dll" (ByVal uJoyID As Integer, ByRef jInfo As JOYINFOEX) As Integer
Public Declare Function joySetCapture Lib "winmm.dll" (ByVal hwnd As IntPtr, ByVal uID As Integer, ByVal uPeriod As Integer, ByVal bChanged As Boolean) As Long
Public Declare Function joyReleaseCapture Lib "winmm.dll" (ByVal id As Long) As Long
Public Shared Function PlayJoyState() As JOYINFOEX
Dim infoJEx As JOYINFOEX
With infoJEx
.dwSize = Marshal.SizeOf(GetType(JOYINFOEX))
.dwFlags = CInt(JOY_RETURNBUTTONS)
.DeviceState = "OK"
End With
Dim result As Integer = joyGetPosEx(False, infoJEx) '返回JOYERR_NOERROR(值为0)
'MsgBox(res)
If r