2017-05-15 4 views
1

Je dois trouver un moyen de convertir les codes d'entrée directe en codes-clés .net. Pardonnez-moi, toute la question d'entrée clé me ​​déroute. L'exemple serait si je prends une clé via:Convertir les codes DirectInput en codes-clés .net

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

et appuyez sur « C » Je reçois un code de touche de 67. Cependant, je développe un plugin pour une application qui renvoie les frappes dans DirectInput format. Cela renvoie "C" comme 46.

J'ai besoin d'un moyen de convertir dinput en format .keycode. Pardonnez-moi si ma terminologie est fausse, mais totalement confus après des heures de googling.

Répondre

0

Nevermind. Trouvé un moyen dans le temps. Étonné n'a pas pu trouver une réponse à cela n'importe où!

<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 

Exemple d'utilisation (en utilisant DirectInput/Scancode pour "C"):

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

Produit 67 (soit le code virtuel pour "C")