c# 捕捉键盘按键

//esc退出窗体
  protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg , System.Windows.Forms.Keys keyData) //激活回车键
  {
   int WM_KEYDOWN=256;       
   int WM_SYSKEYDOWN = 260;

   if(msg.Msg == WM_KEYDOWN | msg.Msg == WM_SYSKEYDOWN)
   {
    switch(keyData)
    {
     case Keys.Escape:
      this.Close();//csc关闭窗体
      break;   

  case Keys.F12:
      messagebox.show("F12");
      break;   

    }  
    
   }
   return false;
  }

posted @ 2014-04-22 13:29  冲向蓝天  阅读(2037)  评论(0编辑  收藏  举报