Esempio n. 1
0
 public Form1()
 {
     InitializeComponent();
     AllocConsole();
     mouse = SetWindowsHookEx(WindowsHookType.WH_KEYBOARD_LL, LLKeyboardProc,
                              GetModuleHandle(null), 0);
     keyboard = SetWindowsHookEx(WindowsHookType.WH_MOUSE_LL, LLMouseProc,
                                 GetModuleHandle(null), 0);
 }
Esempio n. 2
0
    protected WindowsHook(HookType idHook, HookScope scope)
    {
        this.lpfn = this.OnWindowsHook;

        switch (scope)
        {
        case HookScope.LowLevelGlobal:
            this.hhk = SafeHookHandle.SetWindowsHook(idHook, this.lpfn, IntPtr.Zero, 0U);
            return;

        default:
            throw new InvalidEnumArgumentException("scope", (int)scope, typeof(HookScope));
        }
    }
Esempio n. 3
0
    protected WindowsHook(HookType idHook, HookScope scope)
    {
        this.lpfn = this.OnWindowsHook;

        switch (scope)
        {
        case HookScope.LowLevelGlobal:
            IntPtr moduleHandle = NativeMethods.GetModuleHandle(null);
            this.hhk = SafeHookHandle.SetWindowsHook(idHook, this.lpfn, moduleHandle, 0U);
            return;

        default:
            throw new InvalidEnumArgumentException("scope", (int)scope, typeof(HookScope));
        }
    }
Esempio n. 4
0
        public Form1()
        {
            WindowState   = FormWindowState.Minimized;
            ShowInTaskbar = false;
            AllocConsole();

            llms = SetWindowsHookEx(WindowsHookType.WH_KEYBOARD_LL, LLKeyboardProc,
                                    GetModuleHandle(null), 0);
            llkb = SetWindowsHookEx(WindowsHookType.WH_MOUSE_LL, LLMouseProc,
                                    GetModuleHandle(null), 0);

            sz = 8192;
            ri = (RawInput *)Marshal.AllocHGlobal(8192);

            var regs = new RawInputDevice[] {
                new RawInputDevice {
                    UsagePage = HIDUsagePage.Generic,
                    Usage     = HIDUsage.Mouse,
                    Flags     = RawInputDeviceFlags.InputSink |
                                RawInputDeviceFlags.NoLegacy,
                    WindowHandle = this.Handle
                },
                new RawInputDevice {
                    UsagePage = HIDUsagePage.Generic,
                    Usage     = HIDUsage.Keyboard,
                    Flags     = RawInputDeviceFlags.InputSink |
                                RawInputDeviceFlags.NoLegacy,
                    WindowHandle = this.Handle
                }
            };

            RegisterRawInputDevices(
                regs, regs.Length,
                Marshal.SizeOf(typeof(RawInputDevice))
                );

            InitializeComponent();
        }
Esempio n. 5
0
 public static extern IntPtr CallNextHookEx(SafeHookHandle hhk, int nCode, IntPtr wParam, IntPtr lParam);
Esempio n. 6
0
        private void HookGlobal(WindowsHookType hookType, HookCallback callback)
        {
            m_GlobalHookProc = (int nCode, IntPtr wParam, IntPtr lParam) => HookProc(nCode, wParam, lParam, callback);

            SafeHookHandle handle = SetWindowsHookEx(hookType, m_GlobalHookProc, Process.GetCurrentProcess().MainModule.BaseAddress, 0);
        }
Esempio n. 7
0
        private void HookApp(WindowsHookType hookType, HookCallback callback)
        {
            m_AppHookProc = (int nCode, IntPtr wParam, IntPtr lParam) => HookProc(nCode, wParam, lParam, callback);

            SafeHookHandle handle = SetWindowsHookEx(hookType, m_AppHookProc, IntPtr.Zero, GetCurrentThreadId());
        }
Esempio n. 8
0
 internal static extern LRESULT CallNextHookEx(
     HHOOK hhk,
     int nCode,
     WPARAM wParam,
     LPARAM lParam);