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);   //其他键按默认处理
           
        }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM