1

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

Muhammad Touseef
  • 4,357
  • 4
  • 31
  • 75
  • 1
    Also have a look at my answer [here](https://stackoverflow.com/questions/44748723/uwp-dont-fire-click-event-when-pressing-space-like-in-movies-tv-app/44856044#44856044). – Justin XL Jun 30 '17 at 23:41
  • Actually, I just updated that answer with a working demo. Feel free to check it out also. :) – Justin XL Jul 02 '17 at 12:28

1 Answers1

1

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

this.Focus(FocusState.Programmatic); 
igorc
  • 2,024
  • 2
  • 17
  • 29
  • yes I tried that but it doesn't work I guess the default function of key down executes before it. – Muhammad Touseef Jun 30 '17 at 20:18
  • then instead do it after each action which affect your focus on this page, say after full screen toggle - set focus to page. – igorc Jun 30 '17 at 20:21