用ADSW来控制前后左右,J表示开火,J不能连续按
_+表示速度档位、
DateTime _LastPress = DateTime.MinValue; Keys _PrevKey = Keys.None; List<Keys> CtlKeys = new List<Keys>() { Keys.A, Keys.D, Keys.S, Keys.W, Keys.J, Keys.Add, Keys.Subtract }; protected override bool ProcessKeyPreview(ref Message m) { var key = (Keys)m.WParam.ToInt32(); if (!CtlKeys.Contains(key)) { return false; } if (m.Msg == WM_KEYDOWN) { if (key == Keys.J && _PrevKey==key) { var delay=(DateTime.Now - _LastPress).TotalMilliseconds ; Console.WriteLine(delay); if (delay < 1000) { Console.WriteLine("连续按J"); _LastPress = DateTime.Now; return true; } } Console.Write("按下->"); Console.WriteLine(key); _PrevKey = key; _LastPress = DateTime.Now; } if (m.Msg == WM_KEYUP) { Console.Write("释放->"); Console.WriteLine(key); } return base.ProcessKeyPreview(ref m); }