Windows User Action Hook
74 | 75 |A one stop library for global windows user actions such mouse, keyboard, clipboard, & print events
76 | 77 |Kindly report only issues/bugs here . For programming help or questions use StackOverflow with the tag EventHook or Windows-User-Action-Hook.
78 |-
79 |
- API Documentation 80 |
Supported Events
82 |-
83 |
- Keyboard events 84 |
- Mouse events 85 |
- clipboard events 86 |
- application events 87 |
- print events 88 |
Usage
90 |Install by nuget
91 |Install-Package EventHook
92 |
Sample Code:
93 |var eventHookFactory = new EventHookFactory();
94 |
95 | var keyboardWatcher = eventHookFactory.GetKeyboardWatcher();
96 | keyboardWatcher.Start();
97 | keyboardWatcher.OnKeyInput += (s, e) =>
98 | {
99 | Console.WriteLine(string.Format("Key {0} event of key {1}", e.KeyData.EventType, e.KeyData.Keyname));
100 | };
101 |
102 | var mouseWatcher = eventHookFactory.GetMouseWatcher();
103 | mouseWatcher.Start();
104 | mouseWatcher.OnMouseInput += (s, e) =>
105 | {
106 | Console.WriteLine(string.Format("Mouse event {0} at point {1},{2}", e.Message.ToString(), e.Point.x, e.Point.y));
107 | };
108 |
109 | var clipboardWatcher = eventHookFactory.GetClipboardWatcher();
110 | clipboardWatcher.Start();
111 | clipboardWatcher.OnClipboardModified += (s, e) =>
112 | {
113 | Console.WriteLine(string.Format("Clipboard updated with data '{0}' of format {1}", e.Data, e.DataFormat.ToString()));
114 | };
115 |
116 |
117 | var applicationWatcher = eventHookFactory.GetApplicationWatcher();
118 | applicationWatcher.Start();
119 | applicationWatcher.OnApplicationWindowChange += (s, e) =>
120 | {
121 | Console.WriteLine(string.Format("Application window of '{0}' with the title '{1}' was {2}", e.ApplicationData.AppName, e.ApplicationData.AppTitle, e.Event));
122 | };
123 |
124 | var printWatcher = eventHookFactory.GetPrintWatcher();
125 | printWatcher.Start();
126 | printWatcher.OnPrintEvent += (s, e) =>
127 | {
128 | Console.WriteLine(string.Format("Printer '{0}' currently printing {1} pages.", e.EventData.PrinterName, e.EventData.Pages));
129 | };
130 |
131 | //waiting here to keep this thread running
132 | Console.Read();
133 |
134 | //stop watching
135 | keyboardWatcher.Stop();
136 | mouseWatcher.Stop();
137 | clipboardWatcher.Stop();
138 | applicationWatcher.Stop();
139 | printWatcher.Stop();
140 |
141 | //dispose
142 | eventHookFactory.Dispose();
143 |