ToUnicodeEx, and ToAsciiEx make ' into ''
Hello,
I am currently working with keyboard hooking, and created an event for KeyPress, not just KeyDown, and KeyUp. It's defined like this:
Code:
Public Event KeyPress As Forms.KeyPressEventHandler
It uses the "KeyPressEventHandler" instead of "KeyEventArgs" which the KeyDown, and KeyUp event use. The reason for that, is that it has a property named "KeyChar", in which you can put the character/letter that is being pressed, instead of the key code.
My keyboard hook figures out which key is pressed by doing the following:
Code:
If (wParam = &H100) Then '&H100 = WM_KEYDOWN
Dim FinalChar As New System.Text.StringBuilder()
Dim KeyState(256) As Byte
Dim KeyStateStatus As Boolean = GetKeyboardState(KeyState)
If KeyStateStatus Then
ToUnicodeEx(HookStruct.vkCode, HookStruct.scanCode, KeyState, FinalChar, CInt(5), CUInt(0), GetKeyboardLayout(0))
Dim e As Forms.KeyPressEventArgs = New Forms.KeyPressEventArgs(FinalChar.ToString)
TargetDispatcher.BeginInvoke(New RaiseKeyPressDelegate(AddressOf RaiseKeyPress), Windows.Threading.DispatcherPriority.SystemIdle, e)
Handled = Handled Or e.Handled
End If
End If
It works perfectly for letters and such, however, if I press ' in a program like Notepad, it creates ''. This is not how it's supposed to be. It blocks me from creating characters like é (As in my name, René.).
The problem lies in the "ToUnicodeEx" function. If that line is not being executed, it works perfectly fine. I have tried to find ways around it. By using "ToAsciiEx", but that did the exact same thing.
Please help me,
-René
P.S. Click on the function names to go to the definition in the MSDN Library