开发者

Call a method when specific key combination is pressed anywhere in the app, as long as application is currently focused window

开发者 https://www.devze.com 2023-01-18 07:34 出处:网络
My objective is to allow users of my app to bringup what I\'m calling my debug console by pressing CTRL + F11 on their keyboard.

My objective is to allow users of my app to bringup what I'm calling my debug console by pressing CTRL + F11 on their keyboard.

Simply put, I need to call a ToggleDebug(); method, which will enable my debug tracing code and display the window. I'd like for my application to do this at any point when CTRL + F11 is pressed, regardless of where the user currently has focus the cursor as long as my application is the currently focused window.

My app is deployed through Click Once -- so its a partial trust type environment.

In an o开发者_Python百科ld VB6 app, I had been using a wend loop with call to DoEvents() and a windows API call... needless to say, I'm hoping there is a better way now.


You can handle the PreviewKeyDown event of your window.

public MainWindow()
{
    InitializeComponent();
    this.PreviewKeyDown += new KeyEventHandler(MainWindow_PreviewKeyDown);
}

void MainWindow_PreviewKeyDown(object sender, KeyEventArgs e)
{
    if ((e.Key == Key.F11) && (Keyboard.Modifiers == ModifierKeys.Control))
    { 

    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消