通过重写ProcessCmdKey方法,实现按键输入的改变.
如:屏蔽回车键等等.
- protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
- {
- this.textBox1.Focus();
- switch(keyData)
- {
- case Keys.Left:
- System.Windows.Forms.SendKeys.Send("{a}"); //向左改成a
- return true;
- case Keys.Right:
- System.Windows.Forms.SendKeys.Send("{d}"); //向右改成d
- return true;
- case Keys.Up:
- System.Windows.Forms.SendKeys.Send("{w}"); //向上改成w
- return true;
- case Keys.Down:
- System.Windows.Forms.SendKeys.Send("{s}"); //向下改成s
- return true;
- default:
- break;
- }
- return base.ProcessCmdKey(ref msg, keyData); //其他键按默认处理
- }