Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Respond to only the first WM_KEYDOWN notification?

How can a Win32 application respond to only the first WM_KEYDOWN notification? The MSDN docs claim bit 30 "Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is zero if the key is up." but bit 30 is always 0 in my WndProc.

case WM_KEYDOWN:
    // ToDo - stop multiple notifications for repeating keys
    printf("WM_KEYDOWN %i %i", wParam, lParam & 30);
    return 0;

Is lParam & 30 the wrong way to ask for this? Am I doing something else wrong?

like image 363
Nick Van Brunt Avatar asked Nov 30 '22 11:11

Nick Van Brunt


1 Answers

To test bit 30 don't AND with 30, instead AND with 1 << 30.

const bool isBitSet = lParam & (1 << 30);
like image 72
sharptooth Avatar answered Dec 05 '22 06:12

sharptooth