【问题标题】:Convert DirectInput codes into keycodes .net将 DirectInput 代码转换为键码 .net
【发布时间】:2017-10-14 19:00:50
【问题描述】:

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

Private Sub GetKey(sender As Object, e As PreviewKeyDownEventArgs) Handles SnapKeyName.PreviewKeyDown
        Dim KeyCode = e.KeyCode
End Sub

然后按“C”我得到一个键码 67。但是,我正在为一个应用程序开发一个插件,该插件以直接输入格式返回击键。这会将“C”返回为 46。

我需要一种将 dinput 转换为 .keycode 格式的方法。如果我的术语有误,请原谅我,但经过数小时的谷歌搜索后完全混淆了。

【问题讨论】:

    标签: .net keycode directinput


    【解决方案1】:

    没关系。在此期间找到了一种方法。 Astonished 在任何地方都找不到答案!

        <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):

    debug.writeline("VK for Scancode 46: " & MapVirtualKeyEx(46, MapVirtualKeyMapTypes.MAPVK_VSC_TO_VK, Nothing)"
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-29
      • 1970-01-01
      • 2014-09-30
      • 2017-09-23
      • 2012-04-25
      • 2018-11-05
      • 2013-10-24
      • 2020-07-26
      相关资源
      最近更新 更多