并不是所有的按键事件都会转换为WM_CHAR消息,下面是将VK_RETURN VK_DELETE等按键消息转换为WM_CHAR
消息的方法。
响应WM_KEYDOWN消息
if( pMsg->message == WM_KEYDOWN )
{
//vk_retun 和 vk_esc按键成为WM_CHAR消息的方法。
if(pMsg->wParam == VK_RETURN
|| pMsg->wParam == VK_DELETE
|| pMsg->wParam == VK_ESCAPE
|| GetKeyState( VK_CONTROL)//单纯检测CTRL的按下状况,不区分左右。
)
{
::TranslateMessage(pMsg);//made VK_RETURN to CHAR message.....
::DispatchMessage(pMsg);
return TRUE; // DO NOT process further
}
}
下面是解释使用GetKeyState( VK_CONTROL)的好处。
An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the nVirtKey parameter. This gives the status of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. An application can also use the following virtual-key code constants as values for nVirtKey to distinguish between the left and right instances of those keys:
| VK_LSHIFT | VK_RSHIFT |
| VK_LCONTROL | VK_RCONTROL |
| VK_LMENU | VK_RMENU |
本文介绍了一种将特定按键事件如VK_RETURN、VK_DELETE等转换为WM_CHAR消息的方法,并通过响应WM_KEYDOWN消息实现。文中还解释了如何使用GetKeyState(VK_CONTROL)来检测CTRL键的按下状态,同时提供了区分不同虚拟键状态的方法。
2223

被折叠的 条评论
为什么被折叠?



