将VK_RETURN VK_DELETE等按键消息转换为WM_CHAR消息

来源:互联网 发布:linux远程重启服务器 编辑:程序博客网 时间:2024/05/23 22:01

并不是所有的按键事件都会转换为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_LSHIFTVK_RSHIFT
VK_LCONTROLVK_RCONTROL
VK_LMENUVK_RMENU
原创粉丝点击