How can I make GetKeyState understand the capital and noncapital letters

343 views Asked by At

Hey guys I'm using Codeblocks from C. I read https://msdn.microsoft.com/en-us/library/windows/desktop/ms646301(v=vs.85).aspx but I can't understand what I need to change in this code to make it case-sensitive.

void getInput()
{
    while(1)
    {
        if((GetAsyncKeyState('A') & 0x8008)) {
            printf("qwe");
        }
    }
}

Code works and I don't get any errors. Only problem is this doesn't differentiate between pressing a or A, it will print qwe in both cases. How can I fix this?

1

There are 1 answers

0
J. Chomel On

Thanks @EugeneSh., solution is to check the state of VK_CAPITAL, see if Shift is on:

if((GetAsyncKeyState('A') & 0x41) && GetKeyState(VK_CAPITAL)) {
    key_pressed=KEY_A; printf("qwe");
}
if((GetAsyncKeyState('B') & 0x8008) && !GetKeyState(VK_CAPITAL)) {
    key_pressed=KEY_B; printf("asd");
}