Capturing mouse/keyboard events outside of form (app running in background)

Andy Hin picture Andy Hin · Jul 22, 2010 · Viewed 31.3k times · Source

I have an app that runs in the background (minimized/task tray). I need to be able to detect mouse activity (clicks, move) as well as keyboard activity.

What is the best way to do this given the constraint that my window is not "focused" ?

Answer

George Mamaladze picture George Mamaladze · Oct 5, 2011

Take a look at this library http://globalmousekeyhook.codeplex.com/. It is 100% managed c# code to install global mouse and keyboard hooks. It wraps low level hooks into common windows forms keyboard and mouse events.