帮助游戏手柄按钮的代码 [英] help with code for gamepad buttons

查看:97
本文介绍了帮助游戏手柄按钮的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须设计程序来读取游戏手柄的阵列并确定我按下的按钮,目前我有一个使用选择大小写的想法,但是当我组合按钮时代码非常长.我想知道一种更短或更简单的方法来创建此代码.如果有人可以提供帮助,我将非常感激.谢谢

 对于 zize =  0    7 
    选择 案例 zize
    案例  0 
        resultado.Text = Mid(dodge, CByte ( 23 ), CByte ( 2 ))' 道奇是位于标签中的字符串数组
        选择 案例 resultado.Text
        案例 " 
            lengthStr.Text = " 
            GreenButton.Visible = 
            YellowButton.Visible = 错误
            RedButton.Visible = 错误
            BackButton.Visible = 错误
            StartButton.Visible = 错误
            RBButton.Visible = 错误
            LBButton.Visible = 错误
            XBTN.Visible = 错误
        案例 " 
            lengthStr.Text = " 
            RedButton.Visible = 真实
            YellowButton.Visible = 错误
            GreenButton.Visible = 错误
            BackButton.Visible = 错误
            StartButton.Visible = 错误
            RBButton.Visible = 错误
            LBButton.Visible = 错误
            XBTN.Visible = 错误
        案例 " 
            XBTN.Visible = 真实
            YellowButton.Visible = 错误
            RedButton.Visible = 错误
            GreenButton.Visible = 错误
            BackButton.Visible = 错误
            StartButton.Visible = 错误
            RBButton.Visible = 错误
            LBButton.Visible = 错误

        案例 " 
            lengthStr.Text = " 
            YellowButton.Visible = 
            RedButton.Visible = 错误
            GreenButton.Visible = 错误
            BackButton.Visible = 错误
            StartButton.Visible = 错误
            RBButton.Visible = 错误
            LBButton.Visible = 错误
            XBTN.Visible = 错误 



该代码还有更多的情况,因为我必须组合八个按钮.组合从0x00到0xFF,这将是很多情况.我想知道是否有一种方法可以编写出具有相同效果的更好,更动态的代码.每种情况下的陈述都是椭圆形的,代表游戏手柄的每个按钮.如果需要任何其他信息,请告诉我.我将不胜感激.

解决方案

只需将lengthStr.Text的值放入数组中,例如:

const LENGTHSTR as String = {"\0V53J15N", "\0V61J15N", etc...}
const REDBUTTONVALUES = {"01", "03", ...}

Dim code as String
dim index as Integer
code = Mid(dodge, CByte(23), CByte(2))
index = CLng("&H" & code)
lengthStr.Text = LENGTHSTR(index)



为了将按钮设置为可见,您可以执行相同或简单的操作:

RedButton.Visible = Array.IndexOf(REDBUTTONVALUES, Code) >= 0



祝您好运!


您可以通过在开始时将所有按钮都设置为Visible = False来大大简化上面的代码,然后只需在每个case内更改一个设置.

I have to design program to read the array of a game-pad and identify which button I am pressing I currently have an idea using select case but when I combine the buttons the code is extremely long. I will like to know a shorter or easiest way to create this code. If someone can help I will really appreciate. thanks

For zize = 0 To 7
    Select Case zize
    Case 0
        resultado.Text = Mid(dodge, CByte(23), CByte(2)) 'DOdge is a string array located in an label
        Select Case resultado.Text
        Case "01"
            lengthStr.Text = "\0V53J15N"
            GreenButton.Visible = True
            YellowButton.Visible = False
            RedButton.Visible = False
            BackButton.Visible = False
            StartButton.Visible = False
            RBButton.Visible = False
            LBButton.Visible = False
            XBTN.Visible = False
        Case "02"
            lengthStr.Text = "\0V61J15N"
            RedButton.Visible = True
            YellowButton.Visible = False
            GreenButton.Visible = False
            BackButton.Visible = False
            StartButton.Visible = False
            RBButton.Visible = False
            LBButton.Visible = False
            XBTN.Visible = False
        Case "04"
            XBTN.Visible = True
            YellowButton.Visible = False
            RedButton.Visible = False
            GreenButton.Visible = False
            BackButton.Visible = False
            StartButton.Visible = False
            RBButton.Visible = False
            LBButton.Visible = False

        Case "08"
            lengthStr.Text = "\0V123J01N"
            YellowButton.Visible = True
            RedButton.Visible = False
            GreenButton.Visible = False
            BackButton.Visible = False
            StartButton.Visible = False
            RBButton.Visible = False
            LBButton.Visible = False
            XBTN.Visible = False



The code have lots of more case since I have to combine eight buttons. The combinations goes from 0x00 to 0xFF and that will be a lot of case to write. I was wondering if there is a way that I can write a better and more dynamic code that have the same effect. The statements inside each case are oval shapes that represent each button of the game pad. If there''s any additional information needed please let me know. I''ll appreciate any help possible.

解决方案

Simply put the values of lengthStr.Text into an array, something like:

const LENGTHSTR as String = {"\0V53J15N", "\0V61J15N", etc...}
const REDBUTTONVALUES = {"01", "03", ...}

Dim code as String
dim index as Integer
code = Mid(dodge, CByte(23), CByte(2))
index = CLng("&H" & code)
lengthStr.Text = LENGTHSTR(index)



For setting the button visible you could do the same or simply something like:

RedButton.Visible = Array.IndexOf(REDBUTTONVALUES, Code) >= 0



Good luck!


You could simplify the above code considerably by setting all buttons to Visible = False at the start and then you only need to change one setting inside each case.


这篇关于帮助游戏手柄按钮的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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