Advertisement

How do I test bit 31?

Started by May 14, 2001 06:42 AM
0 comments, last by gimp 23 years, 9 months ago
I''ve read in MSDN that a certain keyboard shows call shows the keypress state by testing bit 31 of the lparam. Apparently a define lists it as KF_UP. MSDN says this(Search string : Keystroke Message Flags) Previous Key-State Flag The previous key-state flag indicates whether the key that generated the keystroke message was previously up or down. It is 1 if the key was previously down and 0 if the key was previously up. You can use this flag to identify keystroke messages generated by the keyboard''s automatic repeat feature. This flag is set to 1 for WM_KEYDOWN and WM_SYSKEYDOWN keystroke messages generated by the automatic repeat feature. It is always set to 0 for WM_KEYUP and WM_SYSKEYUP messages. Transition-State Flag The transition-state flag indicates whether pressing a key or releasing a key generated the keystroke message. This flag is always set to 0 for WM_KEYDOWN and WM_SYSKEYDOWN messages; it is always set to 1 for WM_KEYUP and WM_SYSKEYUP messages. So I need to determine: 1) Is the keypress a silly repeat that I need to ignore? 2) Is the keypress event for Pressed or Released. I attempted this but I seem to have an error in my test as when I press a key I get 2 Pressed events:
  
	if ((lparam & KF_REPEAT) == 1)
		return CallNextHookEx(s_KeyboardHook, code, wparam, lparam);

	CWin32Event NewEvent;
	NewEvent.Type = wparam;

	if ((lparam & KF_UP) == 0) // <<<<<<<<<<<<<<<<<<<<<<<<<<

		NewEvent.State = CWin32Event::PRESSED;
	else
		NewEvent.State = CWin32Event::RELEASED;
  
I''ve highlighted the potentially offending code. Is this the correct way of testing a bit? Many thanks Chris
Chris Brodie
The MSDN for WM_KEYDOWN says it is the 14th bit. Dunno if KS_UP is the right one. I always get burned by this because it is different in the mfc OnKeyDown (I think it is 31st bit there) Thanks alot MS!



DSutherland

This topic is closed to new replies.

Advertisement