C# 通过代码捕获键盘方向键操作

来源:互联网 发布:淘宝供货平台 编辑:程序博客网 时间:2024/05/18 00:47

        private void Start_KeyDown(object sender, KeyEventArgs e)
        {       //方向键作用  
            if (e.KeyCode == Keys.P)
            {
                Process p = new Process();
                p.StartInfo = new ProcessStartInfo("winword.exe", "C://1.doc");
                p.Start();
            }
        }

 

        protected override bool ProcessKeyPreview(ref Message m)
        {//方向键作用

            switch (m.WParam.ToInt32())
            {
                case 37:
                    MessageBox.Show("左");
                    break;
                case 38:
                    MessageBox.Show("上");
                    break;
                case 39:
                    MessageBox.Show("右");
                    break;
                case 40:
                    MessageBox.Show("下");
                    break;
            }
            return base.ProcessKeyPreview(ref m);
        }