1

I am developing a WPF application, it is kept minimized in the system tray and I want the window to open when a shortcut is pressed (example: Ctrl + Space).

I have tried using CommandBindings but it only works when the window has the focus, I want the window to stay hidden and show only when the shortcut is pressed.

Xaml Code:

<CommandBinding Command="{x:Static local:SearchWindow.ShowWindowCommand}" Executed="ShowWindowCommandExecuted"/>

C# Code:

public SearchWindow()
{
        ShowWindowCommand.InputGestures.Add(new KeyGesture(Key.Space, ModifierKeys.Control));
        InitializeComponent();
}

private void ShowWindowCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{
    Show();
}
ImMike-SB
  • 21
  • 3
  • 2
    maybe this could help [link](https://stackoverflow.com/a/27309185/2408978) – dba Nov 29 '21 at 16:00
  • Agree with dba. You have to register a global hotkey to the OS using Win32 APIs. However, be careful with your shortcut keys and make sure you aren't using something that could override [the shortcut keys of other apps](https://defkey.com/what-means/ctrl-space) (because yours will override theirs using this methodology). – Tam Bui Nov 29 '21 at 18:19

0 Answers0