VB.net学习笔记之手柄控制:System.Runtime.InteropServices

这篇笔记我整理了好久也没法整理清楚,不过其中一部分要感谢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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值