我正在为个人项目创建游戏,而且我正在使用Windows Form。如果用户点击箭头键,我想每隔几毫秒检查一次。我尝试过Keyboard.IsKeyDown()但它似乎在Windows窗体中不可用。那么有另一种方法吗?
public Form1()
{
InitializeComponent();
fps = new Timer();
fps.Interval = 30;
fps.Tick += Fps_Tick;
fps.Start();
}
private void Fps_Tick(object sender, EventArgs e)
{
int X = playerBlue.Location.X;
int Y = playerBlue.Location.Y;
if (((KeyEventArgs)e).KeyCode == Keys.Right)
{
X += 2;
playerBlue.Location = new Point(X, Y);
}
if (((KeyEventArgs)e).KeyCode == Keys.Left)
{
X -= 2;
playerBlue.Location = new Point(X, Y);
}
}