C#改變按鍵的"鍵值"

 通過重寫ProcessCmdKey方法,實現按鍵輸入的改變.

如:屏蔽回車鍵等等.

  1. protected override bool ProcessCmdKey(ref   Message msg, Keys keyData) 
  2.         { 
  3.             this.textBox1.Focus(); 
  4.             switch(keyData) 
  5.             {                 
  6.                 case Keys.Left: 
  7.                     System.Windows.Forms.SendKeys.Send("{a}");  //向左改成a 
  8.                     return true;                   
  9.                 case Keys.Right: 
  10.                     System.Windows.Forms.SendKeys.Send("{d}"); //向右改成d 
  11.                     return true
  12.                 case Keys.Up: 
  13.                     System.Windows.Forms.SendKeys.Send("{w}");  //向上改成w 
  14.                     return true;   
  15.                 case Keys.Down: 
  16.                     System.Windows.Forms.SendKeys.Send("{s}");  //向下改成s 
  17.                     return true
  18.                 default
  19.                     break
  20.             } 
  21.             return base.ProcessCmdKey(ref msg, keyData);   //其他鍵按默認處理 
  22.              
  23.         } 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章