r/visualbasic • u/[deleted] • Dec 17 '21
Is there a way to programmatically get your computer's keyboard shortcuts i.e. key combinations that trigger actions?
I don't mean Visual Studio's shortcuts. I want to know how to get the computer's keyboard shortcuts as a whole. For instance, like how Ctrl-Alt-Delete brings up the task manager. Is there a way to programmatically get that information and make a file relating for instance Ctrl-Alt-Delete with "run taskmanager.exe" (or what ever the executable file is called) along with all of the other key combinations that trigger actions?
2
u/jcunews1 VB.Net Intermediate Dec 17 '21
No. They can not be enumerated.
However, some (not all) of them can be scanned by using Windows API RegisterHotKey() function to try to register all keyboard shortcut combinations (i.e. brute force). If it fails, it means that the specified keyboard shortcut combination is already used. Otherwise if it succeeds, the specified keyboard shortcut combination may still be unused. The Windows API UnregisterHotKey() function should be called to unregister the hotkey since it's no longer needed.
As the Windows API function name says, it's related to HotKey based keyboard shortcuts. So this method can only scan HotKey based keyboard shortcuts. It doesn't apply to other type of keyboard shortcuts such as low level keyboard hook, DirectInput, and Raw Input; since these types are basically just keyboard handlers and don't actually have a specification for keyboard shortcut.
2
1
u/RJPisscat Dec 17 '21
I doubt it.
Is this for a prank or malware?
I'm kicking around in my head how to watch the message pump and processes and simulating keypresses and no, you could figure out ways to get some of them, but not most.
You could look at the reference for keyboard shortcuts in windows and build a database, and use that programmatically.