1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
Private Declare Function ToAscii Lib "user32.dll" (ByVal uVirtKey As Long, ByVal uScanCode As Long, ByRef lpbKeyState As Byte, ByRef lpwTransKey As Long, ByVal fuState As Long) As Long
Private Declare Function GetKeyboardState Lib "user32.dll" (ByRef pbKeyState As Byte) As Long
Private Function GetCharFromKey(ByVal KeyCode As Integer) As String
Dim KeyBoardState(255) As Byte
Dim Out As Long
If GetKeyboardState(KeyBoardState(0)) <> 0 Then
If ToAscii(KeyCode, 0, KeyBoardState(0), Out, 0) <> 0 Then
If Out <= 255 Then
GetCharFromKey = Chr$(Out)
Else
GetCharFromKey = Left$(StrConv(ChrW$(Out), vbUnicode), 1)
End If
End If
End If
End Function |
Partager