Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# WPF key held

Tags:

c#

key

wpf

I have a problem with key held. Everything works when it's just key down but what about key holding? The code looks like this:

private void Window_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Up || e.Key == Key.Down)
    {
       moveBall(3);
    }
}

Thanks for replies.

like image 901
Paweł Zarzecki Avatar asked Dec 07 '22 04:12

Paweł Zarzecki


1 Answers

The WPF KeyEventArgs class has an IsRepeat property which will be true if the key is being held down.

Example from the article:

// e is an instance of KeyEventArgs.
// btnIsRepeat is a Button.
if (e.IsRepeat)
{
    btnIsRepeat.Background = Brushes.AliceBlue;
}
like image 61
stuartd Avatar answered Dec 10 '22 11:12

stuartd