Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

winapi handling multiple keys

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading