Search code examples
c#xamluwpmediaelementonkeydown

uwp space bar to pause media, triggers last used button


I have set Space bar button to Pause/play my media element in my app, but for example If I use a command with pointer, forexample fullscreen, or mute or any other functionality, apart from pause play, and then when I press space button it pauses/plays media as it is supposed to but it also triggers last command which I used with pointer or touch ( e.g : full screen toggle button). I know why this happens, is because those buttons have focus and then when I press space bar they are triggered as well. My question is how can I prevent this on this specific page? I don't want the space bar or any other key to do anything else on that page, apart from the functions I have assigned through keydown and keyup events.

Thanks in advance


Solution

  • When you detect a spacebar press, just set the focus to the page or some other control:

    this.Focus(FocusState.Programmatic);