P
pamelafluente
I have found on the web a post with this useful way to convert (if
possible) a ScanCode to Ascii. This is remarkably useful to filter keys
under KeyDown/up event.
My problem is that I am not familiar with Platform Invoke and this code
(vb6) needs just a little adjustment (types) to work in VB.NET.
Would anyone be so kind as to show the necessary changes?
Thank you very much in advance!!
-Pamela
'-----------------------------------------------------------------------------------------
Private Declare Function ToAscii Lib "user32" ( _
ByVal uVirtKey As Long, _
ByVal uScanCode As Long, _
lpbKeyState As Byte, _
ByVal lpwTransKey As String, _
ByVal fuState As Long) As Long
Private Declare Function GetKeyboardState Lib "user32" ( _
pbKeyState As Byte) As Long
Function KeyCodeToAscii(ByVal KeyCode As Integer) As String
Dim abKeystate(0 To 255) As Byte
KeyCodeToAscii = " "
GetKeyboardState abKeystate(0)
KeyCodeToAscii = Left$(KeyCodeToAscii, _
ToAscii(KeyCode, _
0, _
abKeystate(0), _
KeyCodeToAscii, _
0))
End Function
'---------------------------------------------------------------------------------------
possible) a ScanCode to Ascii. This is remarkably useful to filter keys
under KeyDown/up event.
My problem is that I am not familiar with Platform Invoke and this code
(vb6) needs just a little adjustment (types) to work in VB.NET.
Would anyone be so kind as to show the necessary changes?
Thank you very much in advance!!
-Pamela
'-----------------------------------------------------------------------------------------
Private Declare Function ToAscii Lib "user32" ( _
ByVal uVirtKey As Long, _
ByVal uScanCode As Long, _
lpbKeyState As Byte, _
ByVal lpwTransKey As String, _
ByVal fuState As Long) As Long
Private Declare Function GetKeyboardState Lib "user32" ( _
pbKeyState As Byte) As Long
Function KeyCodeToAscii(ByVal KeyCode As Integer) As String
Dim abKeystate(0 To 255) As Byte
KeyCodeToAscii = " "
GetKeyboardState abKeystate(0)
KeyCodeToAscii = Left$(KeyCodeToAscii, _
ToAscii(KeyCode, _
0, _
abKeystate(0), _
KeyCodeToAscii, _
0))
End Function
'---------------------------------------------------------------------------------------