首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将DirectInput码转换为.net键码

将DirectInput码转换为.net键码
EN

Stack Overflow用户
提问于 2017-05-15 21:10:28
回答 1查看 750关注 0票数 1

我需要找到一种将directinput代码转换为.net密钥的方法。原谅我,所有的输入都让我困惑。例如,如果我通过以下方式获取一个密钥:

代码语言:javascript
复制
Private Sub GetKey(sender As Object, e As PreviewKeyDownEventArgs) Handles SnapKeyName.PreviewKeyDown
        Dim KeyCode = e.KeyCode
End Sub

然后按"C“键我得到一个67的键码。然而,我正在为一个应用程序开发一个插件,它可以以directinput格式返回击键。这将返回"C“为46。

我需要一种将dinput转换成.keycode格式的方法。如果我的术语是错误的,但在谷歌了几个小时后完全混乱了,请原谅我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-16 18:26:47

不要紧。在平均时间内找到了一条路。惊讶到哪里都找不到答案!

代码语言:javascript
复制
    <DllImport("user32.dll")>
    Private Shared Function MapVirtualKeyEx(uCode As UInteger, uMapType As MapVirtualKeyMapTypes, dwhkl As IntPtr) As UInteger
    End Function

    ''' <summary>
    ''' The set of valid MapTypes used in MapVirtualKey
    ''' </summary>
    Public Enum MapVirtualKeyMapTypes As UInteger
        ''' <summary>
        ''' uCode is a virtual-key code and is translated into a scan code.
        ''' If it is a virtual-key code that does not distinguish between left- and
        ''' right-hand keys, the left-hand scan code is returned.
        ''' If there is no translation, the function returns 0.
        ''' </summary>
        MAPVK_VK_TO_VSC = &H0

        ''' <summary>
        ''' uCode is a scan code and is translated into a virtual-key code that
        ''' does not distinguish between left- and right-hand keys. If there is no
        ''' translation, the function returns 0.
        ''' </summary>
        MAPVK_VSC_TO_VK = &H1

        ''' <summary>
        ''' uCode is a virtual-key code and is translated into an unshifted
        ''' character value in the low-order word of the return value. Dead keys (diacritics)
        ''' are indicated by setting the top bit of the return value. If there is no
        ''' translation, the function returns 0.
        ''' </summary>
        MAPVK_VK_TO_CHAR = &H2

        ''' <summary>
        ''' Windows NT/2000/XP: uCode is a scan code and is translated into a
        ''' virtual-key code that distinguishes between left- and right-hand keys. If
        ''' there is no translation, the function returns 0.
        ''' </summary>
        MAPVK_VSC_TO_VK_EX = &H3

        ''' <summary>
        ''' Not currently documented
        ''' </summary>
        MAPVK_VK_TO_VSC_EX = &H4
    End Enum

示例使用(对“C”使用DirectInput/Scancode ):

代码语言:javascript
复制
debug.writeline("VK for Scancode 46: " & MapVirtualKeyEx(46, MapVirtualKeyMapTypes.MAPVK_VSC_TO_VK, Nothing)"

生成67 (是“C”的虚拟代码)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43988871

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档