INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Getting ASC from WM_KeyDown or WM_KeyUp event?

Getting ASC from WM_KeyDown or WM_KeyUp event?

(OP)
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.

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?

RE: Getting ASC from WM_KeyDown or WM_KeyUp event?

Some code of mine from 2003 may help. Check out the vbKeyboardProc function in thread222-716589: Capture key press in app. If nothing else, look at the MapVirtualKey API call

RE: Getting ASC from WM_KeyDown or WM_KeyUp event?

(OP)
Thanks, I looked at your code and MapVirtualKey but I ran into the same issue when dealing with punctuation.

For better or worse here's my solution, using WM_Char to grab the ASCII value and then passing it on the WM_KeyUp message:

CODE

Static ASCIIVal As Integer
  
  Select Case Msg
    Case WM_Char
      ASCIIVal = wp
    
    Case WM_KeyUp
      Form1.HTMLed1_KeyPress ASCIIVal
      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 

- Andy
___________________________________________________________________
If a man speaks in a forest and there are no women around to hear him - will he still be wrong?

RE: Getting ASC from WM_KeyDown or WM_KeyUp event?

You might like to look at ToAscii API call as well.

RE: Getting ASC from WM_KeyDown or WM_KeyUp event?

Should have come back here earlier with a quick demo of that:

dim result as long
GetKeyboardState KbdScan(0)
ToAscii wp, 0&, KbdScan(0), result, 1&
msgbox chr(result)

RE: Getting ASC from WM_KeyDown or WM_KeyUp event?

Also check your license agreement.

What you are doing in commonly referred to as "hijacking" a piece of software, and in license agreements it is covered under restrictions regarding reverse engineering and circumvention of provided APIs.

Basically this is usually considered piracy.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close