I am trying to write a small space shooter game using C# and WPF. I want to be able to move my space ship up and down by keeping my up- or down key, respectively, pressed. That works. However, if I want to fire using the space button, the movement stops although I'd like it to continue. I am using a key event handler that is registered an implemented as follows:
MainWindow.KeyDown += new KeyEventHandler(OnKeyDown);
...
private void OnKeyDown(object sender, KeyEventArgs e)
{
double Shift = 20;
switch (e.Key)
{
case Key.Down:
if (Y < Model.Height - Geometry.Height - Shift)
Y += Shift;
break;
case Key.Up:
if (Y > Shift)
Y -= Shift;
break;
case Key.Space:
Fire();
break;
}
}
Any ideas on how to acomplish what I want?