2017-05-15 1 views
1

Ich muss einen Weg finden, DirectInput-Codes in. Net-Keycodes zu konvertieren. Verzeihen Sie, das ganze Schlüssel-Input-Ding verblüfft mich. Das Beispiel wäre, wenn ich einen Schlüssel über packen:Konvertieren DirectInput-Codes in Keycodes. NET

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

und drücken Sie „C“ Ich habe einen Schlüsselcode von 67 erhalten jedoch Ich entwickle ein Plugin für eine App, die Tastenanschläge in Directinput-Format zurückgibt. Dies liefert "C" als 46.

Ich brauche eine Möglichkeit, um inputput in .keycode Format zu konvertieren. Verzeihen Sie, wenn meine Terminologie falsch ist, aber nach stundenlangem Googlen völlig verwirrt.

Antwort

0

Vergesst nicht. Hab in der Zwischenzeit einen Weg gefunden. Erstaunt konnte nirgendwo eine Antwort finden!

<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 

Beispiel für die Verwendung (mit Directinput/Scancode für "C"):

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

67 Produziert (der Virtual-Code ist für "C")

Verwandte Themen