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 m开发者_Go百科y application changes the volume.
I use Windows 7 x64 and Visual Studio 2008.
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.
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.
You can use the RAW INPUT method, It is more reliable than GetAsyncKeyState etc.
I wrote this article on Code Project that may be of use to you.
There is both C# and a MASM source code versions available.
精彩评论