Home > Software engineering >  winapi handling multiple keys
winapi handling multiple keys

Time:05-02

I need the program to be able to handle multiple keys at the same time. For this I wrote this code:

    case WM_KEYDOWN:{
        int debug=pix.getMsg().lParam;
        if(debug>=16 && debug<=23){
            char lpKeyState[256];
            ZeroMemory(lpKeyState,256);
            char input[2];
            int symNum=ToAsciiEx(pix.getMsg().wParam,pix.getMsg().lParam,(BYTE*)lpKeyState,(WORD*)input,0,GetKeyboardLayout(0));
            if(symNum==1)
                keyboardInput.push_back(input[0]);
        }
        break;
    }

ToAsciiEx accepts the second parameter of the hardware key scanning code, it says on msdn that WM_KEYDOWN should supposedly pass it through lparam, but something wrong comes to lparam. Where can I get the hardware key scan code or are there other ways to implement this?

CodePudding user response:

As stated in the documentation of WM_KEYDOWN, bits 16 to 23 of lParam contain the scan code.

To extract the scan code from lParam, you can use the following line:

DWORD dwScanCode = ( lParam >> 16 ) & 0xFF;
  • Related