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