I need some shortcut keys in my WPF application. I found this post.
However this link seems to be about application/window level in WPF. For example, the shortcut key is only working in a specific window.
However, what I need is for system&global level. For example, the application is launched but it has been minimized. When my mouse is focused on some other placed in desktop, I click "ctrl+alt+a", then the application will be maximized(or any other operations will be down in the application).
How could I implement such system-level shortcut keys?
#XAMLLOver gives me the correct solution.
Others who needs the global short cut key could check the article below.
Solution for system-level short cut key
Related
I want to capture the PrintScreen button even if the application is minimised or not on focus at all. I've seen some snippets but none of these worked in WPF, only in Winforms. Anyone can give some code to start?
Please refer to the following blog post for an example of how you could implement global hot keys in a WPF application.
Implementing global hot keys in WPF: https://blog.magnusmontin.net/2015/03/31/implementing-global-hot-keys-in-wpf/.
A global, or system-wide, hot key is a key or a combination of keys that is associated with a particular window, which will receive messages whenever the user presses this key or key combination from anywhere in the system.
There are indeed no .NET API:s to register hot keys for your application but there is a native RegisterHotKey method that you can call from managed code using P/Invoke. Please refer to the link for more information.
What you want is called "Global Keyboard Hooks"
there is a pretty good solution here: http://www.codeproject.com/KB/cs/globalhook.aspx
I want to assign a keyboard shortcut to launch my wpf application like window+E for windows explorer.
How can I achieve it?
I know how to assign keys by creating shortcut link of program.But I want the same behavior on every machine .So that if someone presses a Key my WPF program launches.
You have to create a separate application/service, which will have to register a global hotkey, and you can start your application from that app/service.
See this article for more details on how to set up a global hotkey in c#.
Or you can distribute a shortcut with your application with already set up hotkey, and place it in one of those folders during installation:
%UserProfile%\desktop
%AllUsersProfile%\desktop
%UserProfile%\Start Menu
%AllUsersProfile%\Start Menu
This should also work, as this hotkeys are not stored in the registry, but are scanned at logon (and only from those 4 folders) and are actually kept in memory (source: this thread).
Of course this latter option has the drawback to only work with Alt + Ctrl modifiers, as all shourtcut hotkeys.
Say I have started application on Windows (created in WPF for .NET in case that would help), that opens some windows/panels and just runs in a background. User don't want to interact with it constantly, however once in a while needs to urgently execute some actions in it.
Is it possible to bind some key shortcut e.g. alt+key to running application, so on hitting it app gets focus? It doesn't necessarily need to be brought to front, altough that would be nice as well.
"a hotkey that works out of your application" is this what you want?
if so, you need global hotkey that i can reference to!
(Sorry i didn't have enough reputation for commenting!)
I think I found sort of semi-solution, that doesn't need any coding or changing any system settings, but only:
1) keyboard with Windows key
2) possibly forcing user to re-arrange icons on his task bar (or pin my application as one of first 9 applications on his taskbar)
pressing WinKey+digit brings up digit'th application from the taskbar. Pressing it again hides it.
This works for Windows 7.
Obiously doing this way is a bit lame and not customizable at all, but it's always something... Still happy to find better way if there exists such.
I have built an application which listens for a global hot key (Alt + Space currently), when I press the hot key when Google Chrome is in focus it brings my app to focus but also opens Chrome's context menu (right click menu). I used the following dll for implementing the keyboard hook.
Can I prevent this from happening? If so how? This isn't a major problem but if there is a way in which you can clear all existing hot keys tied to that combination then I'd like to learn this.
EDIT
The answer that I selected as being the correct one, is the correct one but for my problem. To correctly implement this feature into a C# WinForm i used this tutorial which was very helpful: http://www.dreamincode.net/forums/topic/180436-global-hotkeys/
The FAQ section of the linked article contains your answer:
Question
I need to suppress some keystrokes after I have processed them.
Answer
Just set the e.Handled property to true in the key events you have
processed. It prevents the keystrokes being processed by other
applications.
There is a small 3rd-party program in the notification area of the taskbar that uses Ctrl-F11 key combination to do a task. The problem is I am using the same shortcut but mine is shadowed by the other one. Basically, I can not do my thing when the user presses Ctrl-F11 even though my window is the one that is currently active. I thought the active window would have the priority in using key combinations, but apparently it is not the case. Considering the program is written in .NET C#, how can I get the shortcut precedence when my application is active?
If you cannot change the Key combination of the tray app and you must use the same in your app.
An extreme approach could be to write a Windows Hook DLL in C++ or Delphi and filter all key presses for Ctrl-F11 and send a message to your app.
This is no small task, there are projects that hook the Windows Keyboard events on Code Project etc. You could adapt one of those. When you receive the keypress and your Window/Form is active you could use SendMessage to message your window.
This would be a last restort. It depends how badly you need it.