I've made a program that runs in the background (No gui, no console, nothing), and I want to make it so that no matter what window is active, if I hit a keyboard shortcut (Lets say, ctrl + shift + alt + space + g), it executes some code. How would I do this?

PS. I'm pretty new to working outside of Forms and stuff, so the simpler, the better. :)

That low level input hook is some tasty stuff, But if you are new to writing applications outside of forms and want simple, that example is far from simple.

The hardest part of writing a good gui free application is that the .net framework won't manually create an event loop for you, so you'll have to create one yourself. That's a bit tricky and unnecessary. You can use a hidden blank form to host the event loop for your application in which case you can use the very simple registerHotKey windows API to handle all your key presses, if you don't want to use a blank form, you can use it as a debug form with a hotkey to show it for app variable information, or as an about box so you can easily tell the version number and list all the shortcuts in the event there are many.

its just an alternate idea, But I would also like to note that the low level system hook described in adatapost's link is a good solid way to handle this as well, it can just get tricky.

commented: To the point. Very good explanation! +11