Application
System.Windows.Forms.Application;
Global Event Filter
public class GlobalEventFilter : IMessageFilter{
public bool PreFilterMessage(ref Message m){
return false; // not filter
}
}
GlobalEventFilter globalFilter = new GlobalEventFilter();
Application.AddMessageFilter(globalFilter);
Some Example
Listen to Global Mouse Move Event
class GlobalMouseMoveHandler : IMessageFilter
{
private const int WM_MOUSEMOVE = 0x200;
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == WM_MOUSEMOVE)
{
Console.WriteLine("mouse move");
}
return false;
}
}
Filter Keydown Event
TBD
Some Common Use Event Key List
WM_MOUSEMOVE=0x0200
WM_LBUTTONDOWN=0x0201
WM_LBUTTONUP=0x0202
WM_LBUTTONDBLCLK=0x0203