• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1001
  • Last Modified:

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
0
PMH4514
Asked:
PMH4514
  • 2
  • 2
2 Solutions
 
AlexFMCommented:
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
 
AndyAinscowCommented:
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now