如何在 sdi mfc 中处理按键 ctrl+shift+A
How to handle Key press ctrl+shift+A in sdi mfc
我是 vc++ 的新手。如何在 sdi mfc 中处理按键 ctrl+shift+A。
对于 ctrl + A 代码工作正常。
case _T('A'):
if(GetKeyState(VK_CONTROL) & 0x8000){
MessageBox(_T("Key Ctrl+A is pressed"));
}
else if((GetKeyState(VK_CONTROL) & 0x8000)&&(GetKeyState(VK_SHIFT) & 0x8000)){
MessageBox(_T("Key Ctrl+Shift+A is pressed"));
}
break;
无论 Shift 键是否按下,您的第一个 if
-子句都是正确的,因此您永远不会到达 else
-子句.如果您更改语句的顺序,您将同时获得:
case _T( 'A' ):
if ( ( GetKeyState( VK_CONTROL ) < 0 ) && ( GetKeyState( VK_SHIFT ) < 0 ) {
MessageBox( _T( "Key Ctrl+Shift+A is pressed" ) );
} else if ( GetKeyState( VK_CONTROL ) < 0 ) {
MessageBox( _T( "Key Ctrl+A is pressed" ) );
}
break;
如果你想全局处理按键,你可以使用Keyboard Accelerators instead. The most straightforward way to set up accelerators is through an ACCELERATORS resource。
我是 vc++ 的新手。如何在 sdi mfc 中处理按键 ctrl+shift+A。 对于 ctrl + A 代码工作正常。
case _T('A'):
if(GetKeyState(VK_CONTROL) & 0x8000){
MessageBox(_T("Key Ctrl+A is pressed"));
}
else if((GetKeyState(VK_CONTROL) & 0x8000)&&(GetKeyState(VK_SHIFT) & 0x8000)){
MessageBox(_T("Key Ctrl+Shift+A is pressed"));
}
break;
无论 Shift 键是否按下,您的第一个 if
-子句都是正确的,因此您永远不会到达 else
-子句.如果您更改语句的顺序,您将同时获得:
case _T( 'A' ):
if ( ( GetKeyState( VK_CONTROL ) < 0 ) && ( GetKeyState( VK_SHIFT ) < 0 ) {
MessageBox( _T( "Key Ctrl+Shift+A is pressed" ) );
} else if ( GetKeyState( VK_CONTROL ) < 0 ) {
MessageBox( _T( "Key Ctrl+A is pressed" ) );
}
break;
如果你想全局处理按键,你可以使用Keyboard Accelerators instead. The most straightforward way to set up accelerators is through an ACCELERATORS resource。