Hi there!

I am writing my own Windows service (used tut from iczelion's page) and it works well, can start it, no error occures and a simple task such as beeping is no problem.

But the time I want to bring a hotkey into the game, nothing works any longer. Even the simple beeping does not work when it should be activated by a hotkey.

Tried all methods I know such as RegisterHotKey or GetAsyncKeyState but it seems my service does not notice any keyboard events.

Now the question: Is this problem solveable? Or is a service generally not able to react on hotkeys (or keyboard events or whatever)?

If there is a solution or anyone has any idea, do not hesitate to post.

regards, ChigpA
Posted on 2008-07-26 16:18:16 by ChigpA
ChigpA, you must have a message loop in thread that calls RegisterHotkey. Please read again about hWnd in RegisterHotkey.
When you call StartServiceCtrlDispatcher (blocking), a new thread is created with entry point in your ServiceMain function. This thread must stay alive until your service is running, and this is the best place for RegisterHotkey and the message loop.
Before you enter the loop, save current thread id in global variable, so it will be easy to terminate by posting a WM_QUIT message from SERVICE_CONTROL_STOP handler.
Posted on 2008-07-27 04:01:53 by sapero
Of course, when using "RegisterHotKey" without defining a "hWnd" you need to get the "WM_HOTKEY" message from the message queue by using "GetMessage" in a loop. I have done such a loop but in another Thread than the "ServiceMain" (done in the Thread that is the service itself), I can't imagine that this is the problem.

But I will try ...
Posted on 2008-07-27 07:28:20 by ChigpA