Exemplo n.º 1
0
        public void InitHook()
        {
            uint id = GetCurrentThreadId();

            MouseProcDelegate += MouseProc;
            mouseHook          = SetWindowsHookEx(WH_MOUSE, MouseProcDelegate, IntPtr.Zero, id);
            if (mouseHook.ToInt32() == 0)
            {
                MessageBox.Show("mouse hook failed");
            }
            KeyboardProcDelegate += KeyboardProc;
            using (System.Diagnostics.Process curProcess = System.Diagnostics.Process.GetCurrentProcess())
                using (ProcessModule curModule = curProcess.MainModule)
                {
                    keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProcDelegate, GetModuleHandle(curModule.ModuleName), 0);
                    if (keyboardHook.ToInt32() == 0)
                    {
                        MessageBox.Show("keboard hook failed");
                    }
                }
        }
Exemplo n.º 2
0
 static extern IntPtr SetWindowsHookEx(int code, HookProcHandle func, IntPtr hInstance, uint threadID);
Exemplo n.º 3
0
 static extern IntPtr SetWindowsHookEx(int code, HookProcHandle func, IntPtr hInstance, uint threadID);
Exemplo n.º 4
0
        public void InitHook()
        {
            uint id = GetCurrentThreadId();

            MouseProcDelegate += MouseProc;
            mouseHook = SetWindowsHookEx(WH_MOUSE, MouseProcDelegate, IntPtr.Zero, id);
            if (mouseHook.ToInt32() == 0)
            {
                MessageBox.Show("mouse hook failed");
            }
            KeyboardProcDelegate += KeyboardProc;
            using (System.Diagnostics.Process curProcess = System.Diagnostics.Process.GetCurrentProcess())
            using (ProcessModule curModule = curProcess.MainModule)
            {
                keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProcDelegate, GetModuleHandle(curModule.ModuleName), 0);
                if (keyboardHook.ToInt32() == 0)
                {
                    MessageBox.Show("keboard hook failed");
                }
            }
        }