K
Kelly Elias
I would like to take a scancode and get the ascii value. I
have tried to use ToAsciiEx, but I first need the virtual
code. To get the virtual code I call MapVirtualKeyEx but
it seems to fail returning a 0. Any idea whats wrong with
this code?
BEGIN CODE-----------
Private Declare Function MapVirtualKeyEx Lib "user32"
Alias "MapVirtualKeyExA" (ByVal uCode As Integer, ByVal
uMapType As Integer, ByVal dwhkl As Integer) As Integer
Private Declare Function ToAsciiEx Lib "user32"
Alias "ToAsciiEx" (ByVal uVirtKey As Integer, ByVal
uScanCode As Integer, ByVal lpKeyState() As Byte, ByVal
lpChar As Integer, ByVal uFlags As Integer, ByVal dwhkl As
Integer) As Integer
Private Declare Function VkKeyScanEx Lib "user32"
Alias "VkKeyScanExA" (ByVal ch As Byte, ByVal dwhkl As
Integer) As Integer
Private Declare Function GetKeyboardState Lib "user32"
Alias "GetKeyboardState" (ByVal pbKeyState() As Byte) As
Integer
Private Declare Function GetKeyboardLayout
Lib "user32" Alias "GetKeyboardLayout" (ByVal dwLayout As
Integer) As Integer
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim scancode As Integer = 9547
Dim keyboardstate(256) As Byte
Dim layout As Integer = GetKeyboardLayout(0)
GetKeyboardState(keyboardstate)
'PROBLEM. 0 is Returned.
Dim virtualkey As Integer = MapVirtualKeyEx
(scancode, 1, layout)
Dim result As Integer
ToAsciiEx(virtualkey, scancode, keyboardstate,
result, 0, layout)
MsgBox(result)
End Sub
--------END CODE
have tried to use ToAsciiEx, but I first need the virtual
code. To get the virtual code I call MapVirtualKeyEx but
it seems to fail returning a 0. Any idea whats wrong with
this code?
BEGIN CODE-----------
Private Declare Function MapVirtualKeyEx Lib "user32"
Alias "MapVirtualKeyExA" (ByVal uCode As Integer, ByVal
uMapType As Integer, ByVal dwhkl As Integer) As Integer
Private Declare Function ToAsciiEx Lib "user32"
Alias "ToAsciiEx" (ByVal uVirtKey As Integer, ByVal
uScanCode As Integer, ByVal lpKeyState() As Byte, ByVal
lpChar As Integer, ByVal uFlags As Integer, ByVal dwhkl As
Integer) As Integer
Private Declare Function VkKeyScanEx Lib "user32"
Alias "VkKeyScanExA" (ByVal ch As Byte, ByVal dwhkl As
Integer) As Integer
Private Declare Function GetKeyboardState Lib "user32"
Alias "GetKeyboardState" (ByVal pbKeyState() As Byte) As
Integer
Private Declare Function GetKeyboardLayout
Lib "user32" Alias "GetKeyboardLayout" (ByVal dwLayout As
Integer) As Integer
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim scancode As Integer = 9547
Dim keyboardstate(256) As Byte
Dim layout As Integer = GetKeyboardLayout(0)
GetKeyboardState(keyboardstate)
'PROBLEM. 0 is Returned.
Dim virtualkey As Integer = MapVirtualKeyEx
(scancode, 1, layout)
Dim result As Integer
ToAsciiEx(virtualkey, scancode, keyboardstate,
result, 0, layout)
MsgBox(result)
End Sub
--------END CODE