I am intercepting the messages from a third party control which doesn't reveal KeyDown, KeyPress or KeyUp events, so that I can replicate those three events by coding them as subroutines. I'm struggling to convert wp (ie. virtual key code) to obtain the correct value for what VB returns as the KeyAscii parameter in the KeyPress event.
Is there a way to convert wp (ie. virtual key code) into an ascii value?
The function below intercepts the Windows messages to the third party control and calls 3 routines called HTMLed1_KeyDown, HTMLed1_KeyPress and HTMLed1_KeyUp. The conversion to an ascii value is flawed, it doesn't work for punctuation for example.
- Andy
___________________________________________________________________
If a man speaks in a forest and there are no women around to hear him - will he still be wrong?
Is there a way to convert wp (ie. virtual key code) into an ascii value?
The function below intercepts the Windows messages to the third party control and calls 3 routines called HTMLed1_KeyDown, HTMLed1_KeyPress and HTMLed1_KeyUp. The conversion to an ascii value is flawed, it doesn't work for punctuation for example.
Code:
Private KbdScan(256) As Byte
Public Function HTMLEdMessage(ByVal hwnd As Long, ByVal Msg As Long, ByVal wp As Long, ByVal lp As Long) As Long
Const WM_KeyDown = 256
Const WM_KeyUp = 257
Dim Ignore As Boolean
Select Case Msg
Case WM_KeyDown
GetKeyboardState KbdScan(0)
ShiftKeys% = -((KbdScan(16) And 128) = 128) - (2 * ((KbdScan(17) And 128) = 128)) - (4 * ((KbdScan(18) And 128) = 128))
Form1.HTMLed1_KeyDown CInt(wp), ShiftKeys%
' This approach does NOT work:...
N$ = LCase$(Chr$(wp))
If ((ShiftKeys% And 1) = 1) Then N$ = UCase$(N$)
Form1.HTMLed1_KeyPress CInt(Asc(N$))
Case WM_KeyUp
GetKeyboardState KbdScan(0)
ShiftKeys% = -((KbdScan(16) And 128) = 128) - (2 * ((KbdScan(17) And 128) = 128)) - (4 * ((KbdScan(18) And 128) = 128))
Form1.HTMLed1_KeyUp CInt(wp), ShiftKeys%
End Select
HTMLEdMessage = CallWindowProc(htmled_lngDefaultHandler, hwnd, Msg, wp, lp)
End Function
- Andy
___________________________________________________________________
If a man speaks in a forest and there are no women around to hear him - will he still be wrong?