Answer the question
In order to leave comments, you need to log in
How to track pressing multiple WPF keys at once?
I'm making a game in WPF and ran into a problem.
We know that you can add a KeyDown event handler to an element.
I have a motion keypress handling function like this:
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Right)
{
this.player.x += this.player.speed;
this.player.character.Margin = new Thickness(this.player.x, this.player.y, 0, 0);
}
if (e.Key == Key.Left)
{
this.player.x -= this.player.speed;
this.player.character.Margin = new Thickness(this.player.x, this.player.y, 0, 0);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question