GetKeyState, how to check high order bit, trap Ctrl-Z

I'm trying to figure this out. should be so simple but I'm at a loss (once again!)

In my PreTranslateMessage(MSG* pMsg) handler, I want to trap CTRL-Z and CTRL-Y

How do I do this? MSGN says to use GetKeyState and check the high-order bit of the return value, I'm not sure how to do that or if it's the right way all together.

Thanks!
-Paul
PMH4514Asked:
Who is Participating?
 
AlexFMConnect With a Mentor Commented:
SHORT state = GetKeyState(...);

if ( state & 0x8000 )     // 1000000000000000 binary
{
    // high bit of state is 1
}
0
 
PMH4514Author Commented:
oh so anding it with 1000000000000000  will get the high-bit.

would my understanding be correct to state that anding it with 0000000000000001  would then get the low bit?
0
 
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
An alternative
      BOOL bIsCtrlKeyDown=::GetAsyncKeyState(VK_CONTROL)<0;
0
 
AlexFMCommented:
Right.
Other way to write this:

if ( state & (SHORT)(1<<15) )    // is bit 15 1 ?
{
}

This gives the same runtime performance because constant 1<<15 is calculated at compile time.
To test bit n use 1<<n.
0
 
PMH4514Author Commented:
oh I get it..

thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.