How to get QChar from KeyPress using WinAPI?

  • Dear all,
    I try to use like that. But it returns same value for both 'a' & 'A'.

    How can I get differentiate them by using WinAPI?
    That's code is OK with Visual Studio C++. Is this a bug in Qt?

    @LRESULT CALLBACK WinHook::keyboardProcedure(int nCode, WPARAM wParam, LPARAM lParam)
    if (nCode == HC_ACTION){
    if (wParam == WM_KEYDOWN){
    BYTE *keyboardState;
    keyboardState = new BYTE[256];
    if (GetKeyboardState(keyboardState)){
    WORD wChar;
    int ra = ToAscii((UINT)p->vkCode,(UINT)p->scanCode,keyboardState,&wChar,0);
    if (ra>0){
    qDebug()<<"wChar is "<<wChar; //return same for both 'a' & 'A'

  • It looks like one of your API calls does not respect the SHIFT flag. You might check if VK_SHIFT resp. VK_LSHIFT or VK_RSHIFT is set in keyboardState.

    Is there any reason you use platform-specific code in the first place?

  • I think,
    already includes VK_SHIFT state. If so, How can I set VK_SHIFT in keyboardState?

    For reason,
    I'm writing windows hook keyboard Input program with Qt. So, I have no choice to use WinAPI.


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.