Ejemplo n.º 1
0
        public HookManager()
        {
            this.LastPressedKeys = new ObservableCollection <string>();

            using (Process curProcess = Process.GetCurrentProcess())
            {
                var module       = curProcess.Modules.Cast <ProcessModule>().Single(m => m.ModuleName.Contains("KeyboardHookDll"));
                var moduleHandle = NativeMethods.GetModuleHandle(module.ModuleName);

                // Setting up delegate to this object
                Hooking.HookFired = this.HookCallback;
                activeDelegate    = Hooking.HookCallback;

                Hooking.HookId = NativeMethods.SetWindowsHookEx(WH_KEYBOARD, activeDelegate, moduleHandle, 0);

                string errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
            }
        }
 public static extern IntPtr SetWindowsHookEx(int idHook, Hooking.HookHandlerDelegate lpfn, IntPtr hMod, uint dwThreadId);