2017-05-15 21 views
1

ダイレクトインプットコードを.netのキーコードに変換する方法を見つける必要があります。私を許してください、キー入力のすべてが私を困惑させます。私は経由でキーをつかむ場合の例は次のようになります。DirectInputコードをキーコードに変換する.net

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

と押して「C」私は私はDirectInputの形式でキーストロークを返すのアプリのためのプラグインを開発しています。しかし、67のキーコードを取得します。これは46として "C"を返します。

私はdinputを.keycode形式に変換する方法が必要です。私の言葉が間違っていても、何時間ものグーグルで混乱したら、私を許してください。

答えて

0

Nevermind。途中で道を見つけた驚いたが、これに答えを見つけることができませんでした! ( "C" のDirectInputの/スキャンコードを使用して)

<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 

使用例:

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

は( "C" の仮想コードである)67を生成

関連する問題