仅在一个程序中从两(2)个操纵杆/游戏手柄获取数据。 [英] Getting data from two(2) joystick/gamepad in one program only.

查看:120
本文介绍了仅在一个程序中从两(2)个操纵杆/游戏手柄获取数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的ff。代码......


*********************************** ***************


Imports System.Runtime.InteropServices



公共类Form1

$
  ;  声明函数joyGetPosEx Lib" winmm.dll" (ByVal uJoyID As Integer,ByRef pji As JOYINFOEX)As Integer



    < StructLayout(LayoutKind.Sequential)GT; _
$
   公共结构JOYINFOEX

       公共dwSize为整数

        Public dwFlags As Integer

       公共dwXpos作为整数

       公共dwYpos As Integer

       公共dwZpos As Integer

       公共dwRpos As Integer

       公共dwUpos As Integer

       公共dwVpos As Integer

       公共dwButtons As Integer

       公共dwButtonNumber为整数

       公共dwPOV为整数

        Public dwReserved1 As Integer

       公共dwReserved2作为整数

   结束结构



    Dim myjoyEX作为JOYINFOEX



    Private Sub Timer1_Tick(ByVal sender As System.Object,ByVal e As System.EventArgs)处理Timer1.Tick



       &NBSP; '获取操纵杆信息

       致电joyGetPosEx(0,myjoyEX)



       使用myjoyEX

            Label10.Text = .dwXpos.ToString          '最多支持六个轴

            Label11.Text = .dwYpos.ToString

            Label12.Text = .dwZpos.ToString

            Label13.Text = .dwRpos.ToString

            Label14.Text = .dwUpos.ToString

            Label15.Text = .dwVpos.ToString

            Label16.Text = .dwButtons.ToString(" X")  '以十六进制打印,因此可以看到与按钮相关联的各个位

            Label17.Text = .dwButtonNumber.ToString  '同时按下的按钮数量为
            Label18.Text =(。dwPOV / 100).ToString     'POV帽子(以1/100度为单位,因此除以100给予度数)

       结束与$
   结束点¥


    Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles MyBase.Load

        myjoyEX.dwSize = 64

        myjoyEX.dwFlags =& HFF'所有信息

        Timer1.Interval = 200  '以5 hz更新

        Timer1.Start()

   结束分

结束班


*************************** ************************************************** *****


该代码仅在一个操纵杆中工作,但如果我的计算机上连接了两个操纵杆,则另一个操纵杆无效。


我该怎么做?


先谢谢!

解决方案

API函数joyGetPosEx有两个参数,第一个参数代表游戏手柄的ID

您可以尝试将代码joyGetPosEx(0,myjoyEX)更改为joyGetPosEx(this.Id,myjoyEX)


This is my ff. codes...

**********************************************************************************

Imports System.Runtime.InteropServices

Public Class Form1

    Declare Function joyGetPosEx Lib "winmm.dll" (ByVal uJoyID As Integer, ByRef pji As JOYINFOEX) As Integer

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure JOYINFOEX
        Public dwSize As Integer
        Public dwFlags As Integer
        Public dwXpos As Integer
        Public dwYpos As Integer
        Public dwZpos As Integer
        Public dwRpos As Integer
        Public dwUpos As Integer
        Public dwVpos As Integer
        Public dwButtons As Integer
        Public dwButtonNumber As Integer
        Public dwPOV As Integer
        Public dwReserved1 As Integer
        Public dwReserved2 As Integer
    End Structure

    Dim myjoyEX As JOYINFOEX

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        ' Get the joystick information
        Call joyGetPosEx(0, myjoyEX)

        With myjoyEX
            Label10.Text = .dwXpos.ToString          'Up to six axis supported
            Label11.Text = .dwYpos.ToString
            Label12.Text = .dwZpos.ToString
            Label13.Text = .dwRpos.ToString
            Label14.Text = .dwUpos.ToString
            Label15.Text = .dwVpos.ToString
            Label16.Text = .dwButtons.ToString("X")  'Print in Hex, so can see the individual bits associated with the buttons
            Label17.Text = .dwButtonNumber.ToString  'number of buttons pressed at the same time
            Label18.Text = (.dwPOV / 100).ToString     'POV hat (in 1/100ths of degrees, so divided by 100 to give degrees)
        End With
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        myjoyEX.dwSize = 64
        myjoyEX.dwFlags = &HFF ' All information
        Timer1.Interval = 200  'Update at 5 hz
        Timer1.Start()
    End Sub
End Class

**********************************************************************************

That code is working in one joystick only but if two joystick attached on my computer, the other one doesn't work.

What will I do?

Thanks in advanced!

解决方案

The API function joyGetPosEx has two parameters, the first parameter represents the ID of the gamepad
You can try changing the code joyGetPosEx(0, myjoyEX) to joyGetPosEx(this.Id, myjoyEX)


这篇关于仅在一个程序中从两(2)个操纵杆/游戏手柄获取数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆