Question

I want to have my program do something when the user hits a certain keybinding, say Control-Shift-f7. But I would like that keybinding to be universal in the sense that the user does not have to bi in the program to use it, the program just runs in the background.

An example of a program that uses this is puush. It runs sort of in the background all the time and then takes a screenshot whenever one presses Control-Shift-3.

How is that possible? I'm on windows by the way :)

Thank you very much for your answers

P.S.: I don't really care what programming language to use. If you give code examples (which I'd of course appreciate) I'd prefer Ruby, c# or java, but I'm very happy with a general answer aswell so that I can research the rest.

Was it helpful?

Solution

What you're looking for is the RegisterHotKey function.

Key combinations inside an application are called accelerators. Key combinations at the system level (global) are called hotkeys.

You can create a window object and never display it (console apps). The callback mechanism uses Windows messages so you'll need a message loop.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top