0
votes

I am developing a WPF application, which has many windows in it. As usual, main window allows to open other windows. I want to create application-level hotkeys (shortcuts), which would open the particular window, and would work in every window of my application.

I have tried using CommandBinding in my MainWindow class, see the example below, but it works if the main window has focus only (as it actually should). I have also tried the second way from this question Application Level shortcut keys in WPF, and created binding to a key "P", but whenever I press P, even if it is a TextBox input text or something like that, the window is opened.

I expect the hotkeys work in every window of my application, but not if it is a text input or something else. I might be wrong using the solution, for which I have provided a link, if so, I would be very grateful to someone who explains me how to use it properly.

1

1 Answers

0
votes

Best practice for hot keys is to use modifiers on them.

I suggest adding the CTRL key as a modifer for your command so the user has to hit CTRL + P to trigger your hot key. And then typing P in a textbox or elsewhere wont cause a problem.

<KeyBinding Modifiers="Ctrl" Key="P" Command="{Binding SomeCommand}"> 
</KeyBinding>