Zzz – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | using System; |
2 | |||
3 | namespace Zzz.Idle |
||
4 | { |
||
5 | public class KeyboardInput : IDisposable |
||
6 | { |
||
7 | #region Static Fields and Constants |
||
8 | |||
9 | private const int WhKeyboardLl = 13; |
||
10 | |||
11 | #endregion |
||
12 | |||
13 | #region Public Events & Delegates |
||
14 | |||
15 | public event EventHandler<EventArgs> KeyboardKeyPressed; |
||
16 | |||
17 | #endregion |
||
18 | |||
19 | #region Private Delegates, Events, Enums, Properties, Indexers and Fields |
||
20 | |||
21 | private readonly WindowsHookHelper.HookDelegate _keyboardDelegate; |
||
22 | |||
23 | private readonly IntPtr _keyBoardHandle; |
||
24 | |||
25 | private bool _disposed; |
||
26 | |||
27 | #endregion |
||
28 | |||
29 | #region Constructors, Destructors and Finalizers |
||
30 | |||
31 | public KeyboardInput() |
||
32 | { |
||
33 | _keyboardDelegate = KeyboardHookDelegate; |
||
34 | _keyBoardHandle = WindowsHookHelper.SetWindowsHookEx( |
||
35 | WhKeyboardLl, _keyboardDelegate, IntPtr.Zero, 0); |
||
36 | } |
||
37 | |||
38 | public void Dispose() |
||
39 | { |
||
40 | Dispose(true); |
||
41 | } |
||
42 | |||
43 | protected virtual void Dispose(bool disposing) |
||
44 | { |
||
45 | if (!_disposed) |
||
46 | { |
||
47 | if (_keyBoardHandle != IntPtr.Zero) |
||
48 | { |
||
49 | WindowsHookHelper.UnhookWindowsHookEx(_keyBoardHandle); |
||
50 | } |
||
51 | |||
52 | _disposed = true; |
||
53 | } |
||
54 | } |
||
55 | |||
56 | ~KeyboardInput() |
||
57 | { |
||
58 | Dispose(false); |
||
59 | } |
||
60 | |||
61 | #endregion |
||
62 | |||
63 | #region Private Methods |
||
64 | |||
65 | private IntPtr KeyboardHookDelegate(int code, IntPtr wParam, IntPtr lParam) |
||
66 | { |
||
67 | if (code < 0) |
||
68 | { |
||
69 | return WindowsHookHelper.CallNextHookEx(_keyBoardHandle, code, wParam, lParam); |
||
70 | } |
||
71 | |||
72 | KeyboardKeyPressed?.BeginInvoke(this, EventArgs.Empty, ar => { }, null); |
||
73 | |||
74 | return WindowsHookHelper.CallNextHookEx(_keyBoardHandle, code, wParam, lParam); |
||
75 | } |
||
76 | |||
77 | #endregion |
||
78 | } |
||
79 | } |