C#通过重写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);   //其他键按默认处理
           
        }

你可能感兴趣的:(process)