views:

105

answers:

2

I want to create an application. This application has to do something when a user presses special keys on keyboard or/and uses scroll wheel. This application is a service. It has no windows. I want to catch any keyboard or mouse events which were designed with other applications.

For example, you are watching TV by 3rd party application. If you press Ctrl + Shift and use scroll wheel my application changes the volume.

I use Windows 7 x64 and Visual Studio 2008.

+1  A: 

You can call SetWindowsHookEx() to be notified when various events occur. You probably want to use the keyboard hook and the mouse hook to watch for mouse events.

Andy
It's not clear. I call `hhk=::SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc1, 0, 0);`. But this does not work. Could you give me more info?
Alexey Malistov
It would probably be better to use the normal keyboard hook and the mouse hook. The low level keyboard hook might be called too early - I'm not sure if it will give you the info you need, or not. There seems to be an example linked from the MSDN page - maybe that will help?
Andy
+2  A: 

If your application is a true Win32 service, then on Vista and beyond, the application won't receive keyboard or mouse events - to close a security hole (search for "shatter attack"), Microsoft isolated all services to prevent them from interacting with the user.

You'll need to have your application run in the session with the interactively logged on user.

Larry Osterman