2017-05-15 22 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의 키 코드를 얻을. 이것은 "C"를 46으로 반환합니다.

d 입력을 .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)를 생성