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
QUESTION
How does one programmatically interrogate Win7 to get a list of all currently active global keyboard shortcuts?
Scenario
In many versions of Windows there is the so called "Windows Key", a.k.a. "flag", "start key", et cetera.
Microsoft has a support article "Keyboard shortcuts for Windows" that lists many of these under the section "Microsoft Natural Keyboard keys", as well as many others the do not involve using the "Windows Key" such as the global Ctrl+C, et cetera.
Other keyboard shortcuts can be discovered by accident. For example, Windows Key + Left arrow or Right arrow in Win7 moves the focused window around the display, and, with multiple monitors, from one display to the next.
Still other keyboard shortcuts can be found in the "options" settings, for example, Left-Ctrl+Alt+K is the default for "Show KeePass Window".
Additionally, there may be hardware specific keyboard shortcuts, for example, on my laptop, Fn+F8 toggles speaker muting.
Stolen Keyboard Shortcuts
When Snagit is running, I've configured PrtSc as my shortcut, but when Visual Studio(VS) is running, it steals PrtSc from Snagit.
Two time consuming methods of manually discovered keyboard shortcuts
(a) Global keyboard shortcuts can be discovered by having only the desktop and a couple of windows open and trying various key combinations.
(b) in VS, many VS keyboard shortcuts can be discovered by trying various combinations in the keyboard shortcuts window where, if a combination is already used, VS will notify one about the current usage for that combination.
Two reasons for wanting to discover all currently active global keyboard shortcuts
(a) to avoid annoying accidents like Windows Logo Key+L which locks the computer.
(b) to determine which keys are currently still available for assignment.
This is a quite interesting but difficult issue. The Windows Operating System apparently does not offer a direct way to do this via maybe EnumerateHotKeys? However, when the RegisterHotKey function is called, there's a search using __FindHotKey. So it may be possible to hack into this function and find out available hot keys. See this C example. There's also a complete example in assembly languagedownloadable from here but this is likely not to work in Windows Vista +.
Another method is to scan all the shortcuts in the system. This can really take a long time if you want to scan all shortcuts on the system. However you can still grab most of them using the common shortcut directories such as:
%AllUsersProfile%\desktop %UserProfile%\Start Menu
%AllUsersProfile%\Start Menu %appdata%\Microsoft\Internet
Explorer\Quick Launch %appdata%\Microsoft\Internet Explorer\Quick
Launch\User Pinned\StartMenu %appdata%\Microsoft\Internet
Explorer\Quick Launch\User Pinned\TaskBar
Here's a simple program I just wrote that scans all the shortcuts in the UserProfile directory.
using IWshRuntimeLibrary;//You can download this library from http://www.codeproject.com/KB/dotnet/ShellLink/ShellLink.zip
WshShell wsh = new WshShellClass();
var files = GetFiles(Environment.ExpandEnvironmentVariables("%userprofile%"), "*.lnk*");
foreach (string f in files)
{
try
{
WshShortcut wa = wsh.CreateShortcut(f) as WshShortcut;
if (wa.Hotkey != "")
{
MessageBox.Show("Shortcut Found! - " + wa.Hotkey, wa.TargetPath);
}
}
catch
{
continue;
}
}
Grap the GetFiles method from here if you want to use it. The major advantage of the method is just to avoid directory permission issues.
Good luck.
The first obvious way is to create a shortcut (.LNK) file in the Start Menu (or on Desktop) and in the Properties dialog to assign a keyboard shortcut (let's say Ctrl + Alt + F10).
However, this way seems to have different issues, such as the shortcut key does not work if I'm pressing it in Firefox in Full Screen Mode (F11) or when playing a Flash video (such as a Youtube video) in Full Screen Mode.
Are there any other built-in ways in Windows to define a custom global shortcut? Maybe in the registry, etc.?
I'd like to avoid using RegisterHotKey because it would require my C# program (even simple .NET programs take a lot of memory) to always run in the background waiting for the hotkey (plus it must start with Windows, etc.)
Or are there third-party programs written in native code that are very small and can be deployed with my program to help me accomplish the task of having a hotkey for my C# program?
Here is a solution from a related Stackoverflow post:
Best way to tackle global hotkey processing in c#?
It links to a blog where you can download a library that does what you are looking for.
I created one desktop application in C# with installation version.
I installed this application onto the machine. Now I want to open this application by pressing the Ctrl key of keyboard.
That is when the user press the Ctrl key my installed application is open.
How can I open a particular search page of my application by pressing a particular key of the keyboard?
Like the Picasa software.
Well this is no programming but a Windows feature. You have to define a shortcut for that application by opening the property page of that shortcut. There under the shortcut tab you can define the shortcut keys.
For the search key you probably have to attach your main form to the KeyPress event.
Defining key in Shortcut (link) properties would work but not if want just the Control key to activate. To do this you need another application, running in background and auto-starting that listens to keyboard events (hooks).
I wan't to customize the icon displayed within the windows 7 taskbar.
When my app is running, I can do it by changing main window icon but, when the app is pinned, the exe's icon is displayed.
How can I set the taskbar icon for my app to an icon different from the one embedded within the exe ?
Not tried, this solution may work but looks dirty.
Edit :
Our app is compiled once but depending on config file, features are enabled or not so it's a product or another. We do not want to compile one exe for each product.
The solution above may not work as many instances of my app can be installed in different pathes (so you end up with the same exe file name but different icons!), is this registry key poorly designed or am I missing something?
EDIT The info below is a bit obsolete; all new Windows 7 bits are now available as a managed API, available here: http://code.msdn.microsoft.com/WindowsAPICodePack
There is a series of articles on the new Taskbar API by the debugging guru Sasha Goldshtein. You should have a look at the Overlay Icons and Progress Bars API.
You can download the sample code from Windows 7 Taskbar Developer Resources on Microsoft Code. What you're looking for is the IMClient sample:
The IMClient sample demonstrates how
taskbar overlay icons and taskbar
progress bars can light up an
application’s taskbar button instead
of relying on an additional dialog or
on an icon in the system notification
area (tray).
(source: microsoft.co.il)
(source: microsoft.co.il)
(source: microsoft.co.il)
I believe this should help you achieve what you want.
When you pin an application to the TaskBar, it simply creates a shortcut in the following directory:
C:\Users\<User Name>\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar
You should be able to identify where the shortcut is (ie, get KnownFolders and work from there. UserAppData should be the one), and then using P/Invoke (IShellLink), you can alter the icon that the shortcut is setup to use. The machine might need a reboot for this to take effect, but it should work.
If you hold down Shift while right-clicking on the pinned application, and select Properties, you can see the Change Icon button for the shortcut. This is basically what you need to emulate with code.
All of these things can definately be done with code, but whether you think they're any better than the registry setting is up to you.
You can do this by using the library called "Windows 7 Bridge" which is based on the "Windows Vista Bridge".
These are managed wrappers around all the Vista and Windows 7 native functions.
More info can be found here
I don't know if I'm understanding your problem but..
If you create an application and put the icon property of the main window, that icon will appear in the taskbar also. But, if you pin-it to the taskbar, that icon dissapear. Am I right? If so, go to the project properties and in the application tab, put the icon that you want for the exe. Now, you will see that icon in the taskbar when pinned.
I Use the same icon for both things :P
As far as I can tell, for some reason you can't change the icon for a program that's already pinned to the taskbar. To do it, just unpin the program, locate it in the start menu, right click - properties - change icon. then re-pin it to the taskbar, and it will have the new icon!
Have a look at this blog. He does a series of blog posts about programming the Windows 7 taskbar, so maybe that will point you in the right direction.
I can't test this right now unfortunately, but perhaps just creating a regular, good old shortcut might solve the problem? Create a shortcut to the app, change the icon, then pin the shortcut instead of the app itself?
Will check when I can next get access to my Windows 7 machine...
Right click on the pinned icon, in the popup you see the programs title, there right click again and go to properties. There you are able to change the icon by clicking on the button
"change icon". For me it needed a reboot to finish the changes.
If you want to have a shortcut in the taskbar that goes directly to somewhere useful, such as your "My Documents" directory. The easy fix . . .
Drop a folder into the taskbar ( which creates a shortcut to images ). Navigate to the directory where that shortcut was placed, right click on the shortcut and select "properties" to change the target. Select the "general" tab to change the name of the shortcut. The shortcut was placed here:
C:\Users[user]\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar
You can navigate to this directory and edit the properties of the "images" shortcut.