Link to home
Start Free TrialLog in
Avatar of retinax
retinax

asked on

ToUnicode API

Hello,

Trying to read keystrokes for other languages in VB6:

===================================================
Public Declare Function ToUnicode Lib "user32" (ByVal wVirtKey As Long, ByVal wScanCode As Long, lpKeyState As Byte, ByVal pwszBuff As String, ByVal cchBuff As Long, ByVal wFlags As Long) As Long

SomeFunction()

 GetKeyboardState KeyboardState(0)

strKeyUnicode = Space(100)

lReply = ToUnicode(Hookstruct.vkCode, Hookstruct.scanCode, KeyboardState(0), StrPtr(strKeyUnicode), Len(strKeyUnicode), 0)

end function
========================

strKeyUnicode is still empty after the call, and lReply=1. Plus program crashes on it. Please help.

Thank you
ASKER CERTIFIED SOLUTION
Avatar of Dana Seaman
Dana Seaman
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can see this in the second link but it is important that you cache the KeyCode in WM_KEYDOWN since you will need this value in WM_CHAR where you finally call Function ToCharacterEX which uses API ToUnicodeEx.
Avatar of retinax
retinax

ASKER

Ok, the code that worked is in addition to the module at:

https://www.experts-exchange.com/questions/22498444/Trap-which-key-is-pressed-in-different-keyboard-layouts.html

Private Type KBDLLHOOKSTRUCT
    vkCode As Long
    scanCode As Long
    Flags As Long
    time As Long
    dwExtraInfo As Long
End Type
...
 Case WM_KEYDOWN
      m_KeyCodeCached = LOWORD(wParam)
      Call CopyMemory(Hookstruct, ByVal lParam, Len(Hookstruct))
      lReply = ToAscii(Hookstruct.vkCode, Hookstruct.scanCode, KeyboardState(0), KeyAscii, 0)
      sChar = ToCharacterEx(KeyAscii, Hookstruct.vkCode, 0&)
....