how to detect if key was or was not pressed previously?

Regarding WM_KEYDOWN message I have read:
"In all four of the keyboard messages discussed so far, the wParam parameter contains the virtual-key code of the key. The lParam parameter contains some miscellaneous information packed into 32 bits. You typically do not need the information in lParam. One flag that might be useful is bit 30, the "previous key state" flag, which is set to 1 for repeated key-down messages."
https://msdn.microsoft.com/en-us/lib...=vs.85%29.aspx

So I did a small test:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
switch (msg)
{
case WM_KEYDOWN:
 ret = 0;
 int b;
 b = 1 << 29;
 if ( lParam & (1 << 29))
	{
	data.initiatedCount++;      
	}

 short keystate;
 if ( wParam == VK_CONTROL)
 {
 data.ctrlPressed = true;
 keystate = GetKeyState(VK_CONTROL);
 if (keystate & PRESSED)
      {
      data.ctrlPressed = data.ctrlPressed; 
      }
}


So I have shifted the 1 to left and I got number 536870912.
1
2
3
4
5
decimal: 536870912
binary:
100000000000000000000000000000
1	 2	   3
123456789012345678901234567890


Then I expect, that if I press ctrl and hold, the debugger should jump to line 9 because the message should be send repeatedly so the first result should be 0 and the second should be 1. Am I right in my assumption? But the result is false so nothing happens. Why? Is the message send no repeatedly? And so status 0 is correct?
bit 30
(1 << 29)
A slight discrepancy here. Bit 29 is always 0.
I thought the mask in binary should have 30 digits? (1 << 30) would give 31 digits. Note: I tested it with (1 << 30) and it works now. Thanks.
Last edited on
Bits are counted from 0, like array elements.
Ah, so it is the digit 31 counted from right to left...
Topic archived. No new replies allowed.