1: // Structure contain information about low-level keyboard input event
2: [StructLayout(LayoutKind.Sequential)]
3: private struct KBDLLHOOKSTRUCT
4: {
5: public Keys key;
6: public int scanCode;
7: public int flags;
8: public int time;
9: public IntPtr extra;
10: }
11:
12: //System level functions to be used for hook and unhook keyboard input
13: private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
14: [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
15: private static extern IntPtr SetWindowsHookEx(int id, LowLevelKeyboardProc callback, IntPtr hMod, uint dwThreadId);
16: [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
17: private static extern bool UnhookWindowsHookEx(IntPtr hook);
18: [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
19: private static extern IntPtr CallNextHookEx(IntPtr hook, int nCode, IntPtr wp, IntPtr lp);
20: [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
21: private static extern IntPtr GetModuleHandle(string name);
22: [DllImport("user32.dll", CharSet = CharSet.Auto)]
23: private static extern short GetAsyncKeyState(Keys key);
24:
25:
26: //Declaring Global objects
27: private IntPtr ptrHook;
28: private LowLevelKeyboardProc objKeyboardProcess;