Beispiel #1
0
        /// <summary>
        /// Creates a two input hooks: mouse and keyboard. Requires running Message Loop on the calling thread.
        /// </summary>
        public HardwareHook()
        {
            _proc = HookCallback;

            _keyboardHookId = WinAPI.SetKeyboardHook(_proc);
            _mouseHookId    = WinAPI.SetMouseHook(_proc);
        }
Beispiel #2
0
        public void Initialize()
        {
            _callbacks   = new List <OnKeyActionDelegate>();
            _proc        = HookCallback;
            _hookID      = SetHookKeyboard(_proc);
            _mouseHookId = SetHookMouse(_proc);

            // Make sure the hooks succeeded
            while (_hookID == IntPtr.Zero)
            {
                MessageBoxResult dr = MessageBox.Show("Warning, failed to hook keyboard. Should I try again?", "Error", MessageBoxButton.YesNo);
                if (dr != MessageBoxResult.Yes)
                {
                    break;
                }
                _hookID = SetHookKeyboard(_proc);
            }

            while (_mouseHookId == IntPtr.Zero)
            {
                MessageBoxResult dr = MessageBox.Show("Warning, failed to hook mouse. Should I try again?", "Error", MessageBoxButton.YesNo);
                if (dr != MessageBoxResult.Yes)
                {
                    break;
                }
                _mouseHookId = SetHookMouse(_proc);
            }
        }
 private IntPtr SetKeyboardHook(LowLevelProc proc)
 {
     using (Process curProcess = Process.GetCurrentProcess())
         using (ProcessModule curModule = curProcess.MainModule)
         {
             return(SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0));
         }
 }
Beispiel #4
0
 private IntPtr SetHookMouse(LowLevelProc proc)
 {
     using (Process curProcess = Process.GetCurrentProcess())
         using (ProcessModule curModule = curProcess.MainModule) {
             return(SetWindowsHookEx(WH_MOUSE_LL, proc,
                                     GetModuleHandle(curModule.ModuleName), 0));
         }
 }
Beispiel #5
0
 /// <summary>
 /// Uses SetWindowsHookEx to set a mouse hook with the given
 /// LowLevelProc callback method.
 /// </summary>
 /// <param name="proc">The callback method to be called.</param>
 /// <returns>If the function succeeds, the return value is the handle to the hook procedure.
 /// If the function fails, the return value is NULL.</returns>
 public static IntPtr SetMouseHook(LowLevelProc proc)
 {
     using (var curProcess = Process.GetCurrentProcess())
         using (var curModule = curProcess.MainModule)
         {
             return(SetWindowsHookEx(WHMOUSELL, proc, GetModuleHandle(curModule.ModuleName), 0));
         }
 }
Beispiel #6
0
 protected static IntPtr SetHook(LowLevelProc proc, int WH_LL)
 {
     using (Process curProcess = Process.GetCurrentProcess())
     using (ProcessModule curModule = curProcess.MainModule)
     {
         return SetWindowsHookEx(WH_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
     }
 }
Beispiel #7
0
 private static IntPtr SetHook(int idHook, LowLevelProc proc)
 {
     using (Process curProcess = Process.GetCurrentProcess())
         using (ProcessModule curModule = curProcess.MainModule) {
             return(SetWindowsHookEx(idHook, proc,
                                     GetModuleHandle(curModule.ModuleName), 0));
         }
 }
Beispiel #8
0
 private static IntPtr SetHook(LowLevelProc proc, bool Keyboard)
 {
     using (System.Diagnostics.Process curProcess = System.Diagnostics.Process.GetCurrentProcess())
         using (System.Diagnostics.ProcessModule curModule = curProcess.MainModule)
         {
             return(SetWindowsHookEx(Keyboard ? WH_KEYBOARD_LL : WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0));
         }
 }
Beispiel #9
0
 public static IntPtr SetMouseHook(LowLevelProc proc)
 {
     using (Process curProcess = Process.GetCurrentProcess())
         using (ProcessModule curModule = curProcess.MainModule)
         {
             return(SetWindowsHookEx((int)HardwareHookType.WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0));
         }
 }
        private void InitializeHooks()
        {
            _lowLevelMouseProc = MouseHookCallback;
            _mouseHookID       = SetMouseHook(_lowLevelMouseProc);

            _lowLevelKeyboardProc = KeyboardHookCallback;
            _keyboardHookID       = SetKeyboardHook(_lowLevelKeyboardProc);
        }
 private IntPtr SetHook(LowLevelProc proc)
 {
     using (Process curProcess = Process.GetCurrentProcess())
         using (ProcessModule curModule = curProcess.MainModule)
         {
             return(WinApiMethods.SetWindowsHookEx((int)HookType.WH_KEYBOARD_LL, proc, WinApiMethods.GetModuleHandle(curModule.ModuleName), 0));
         }
 }
Beispiel #12
0
 private static IntPtr SetKeyboardHook(LowLevelProc proc)
 {
     using (var curProcess = Process.GetCurrentProcess())
         using (var curModule = curProcess.MainModule)
         {
             return(SetWindowsHookEx((int)GlobalHookTypes.WH_KEYBOARD_LL, proc,
                                     GetModuleHandle(curModule.ModuleName), 0));
         }
 }
Beispiel #13
0
        public HookType()
        {
            this.HookCallback = DefaultHookCallback;

            this._proc = new LowLevelProc(this.HookCallback);

            //Init
            _hookID = this.SetHook();
        }
Beispiel #14
0
        protected override void DisposeUnmanagedResources()
        {
            base.DisposeUnmanagedResources();

            WinAPI.UnhookWindowsHookEx(_keyboardHookId);
            WinAPI.UnhookWindowsHookEx(_mouseHookId);

            _proc = null;
        }
Beispiel #15
0
        public static IntPtr SetWindowsHook(HookType hookType, LowLevelProc callback)
        {
            using var currentProcess = Process.GetCurrentProcess();

            using var currentModule = currentProcess.MainModule;
            var handle = Kernel32.GetModuleHandle(currentModule?.ModuleName);
            var hookId = SetWindowsHookLowLevel(hookType, callback, handle, 0);

            return(hookId);
        }
Beispiel #16
0
 public static bool HookStart()
 {
     using (Process curProcess = Process.GetCurrentProcess())
         using (ProcessModule curModule = curProcess.MainModule) {
             var handle = GetModuleHandle("user32");
             _proc   = HookCallback;
             _hookID = SetWindowsHookEx(WH_MOUSE_LL, _proc, handle, 0);
             return(_hookID != IntPtr.Zero);
         }
 }
 public static IntPtr SetWindowsHook(int hookType, LowLevelProc callback)
 {
     IntPtr hookId;
     using (var currentProcess = Process.GetCurrentProcess())
     using (var currentModule = currentProcess.MainModule)
     {
         var handle = NativeMethods.GetModuleHandle(currentModule.ModuleName);
         hookId = NativeMethods.SetWindowsHookEx(hookType, callback, handle, 0);
     }
     return hookId;
 }
Beispiel #18
0
        public static IntPtr SetWindowsHook(HookType hookType, LowLevelProc callback)
        {
            IntPtr hookId;

            using (var currentProcess = System.Diagnostics.Process.GetCurrentProcess())
                using (var currentModule = currentProcess.MainModule)
                {
                    var handle = Kernel32.GetModuleHandle(currentModule.ModuleName);
                    hookId = SetWindowsHookLowLevel(hookType, callback, handle, 0);
                }
            return(hookId);
        }
Beispiel #19
0
        public static IntPtr SetWindowsHook(int hookType, LowLevelProc callback)
        {
            IntPtr hookId;

            using (var currentProcess = Process.GetCurrentProcess())
                using (var currentModule = currentProcess.MainModule)
                {
                    var handle = NativeMethods.GetModuleHandle(currentModule.ModuleName);
                    hookId = NativeMethods.SetWindowsHookEx(hookType, callback, handle, 0);
                }
            return(hookId);
        }
Beispiel #20
0
        private Hook()
        {
            _kproc = kHookReception;
            _mproc = mHookReception;

            _khookID = setkHook(_kproc);
            _mhookID = SetmHook(_mproc);

            onKeyUp = new LinkedList <OnKeyDelegate>();
            onKeyDn = new LinkedList <OnKeyDelegate>();
            onMouse = new LinkedList <OnMouseDelegate>();
        }
Beispiel #21
0
        public void Init()
        {
            m_OverlayWindow = new MyOverlayWindow();

            m_ControllerManager = new ControllerManager();

            RunConfig();

            m_OverlayWindow.onDrawGraphics += Update;

            m_KeyboardProc   = KeyboardHookCallback;
            m_KeyboardHookID = SetKeyboardHook(m_KeyboardProc);

            m_OverlayWindow.Run();
        }
Beispiel #22
0
        /// <summary>
        // Register key capture method.
        /// </summary>
        /// <returns>If successful, a Desktop object, otherwise, null.</returns>
        private static void RegisterKeyboardHookMethod()
        {
            // Get Current Module
            ProcessModule objCurrentModule = Process.GetCurrentProcess().MainModule;

            // Assign callback function each time keyboard process
            objKeyboardProcess = new LowLevelProc(CaptureKey);

            // Assign callback function each time mouse process
            objMouseProcess = new LowLevelProc(CaptureMouseButton);

            // Setting Hook of Keyboard Process for current module
            ptrKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, objKeyboardProcess,
                                               GetModuleHandle(objCurrentModule.ModuleName), 0);

            ptrMouseHook = SetWindowsHookEx(WH_MOUSE_LL, objMouseProcess,
                                            GetModuleHandle(objCurrentModule.ModuleName), 0);
        }
Beispiel #23
0
        public void Initialize()
        {
            _callbacks = new List<OnKeyActionDelegate>();
            _proc = HookCallback;
            _hookID = SetHookKeyboard(_proc);
            _mouseHookId = SetHookMouse(_proc);

            // Make sure the hooks succeeded
            while (_hookID == IntPtr.Zero) {
                MessageBoxResult dr = MessageBox.Show("Warning, failed to hook keyboard. Should I try again?", "Error", MessageBoxButton.YesNo);
                if (dr != MessageBoxResult.Yes)
                    break;
                _hookID = SetHookKeyboard(_proc);
            }

            while (_mouseHookId == IntPtr.Zero) {
                MessageBoxResult dr = MessageBox.Show("Warning, failed to hook mouse. Should I try again?", "Error", MessageBoxButton.YesNo);
                if (dr != MessageBoxResult.Yes)
                    break;
                _mouseHookId = SetHookMouse(_proc);
            }
        }
 private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelProc lpfn, IntPtr hmod, uint dwThread);
Beispiel #25
0
 private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelProc lpfn, IntPtr hMod, uint dwThreadId);
Beispiel #26
0
 /// <summary>
 /// Uses SetWindowsHookEx to set a mouse hook with the given
 /// LowLevelProc callback method.
 /// </summary>
 /// <param name="proc">The callback method to be called.</param>
 /// <returns>If the function succeeds, the return value is the handle to the hook procedure. 
 /// If the function fails, the return value is NULL.</returns>
 public static IntPtr SetMouseHook(LowLevelProc proc)
 {
   using (var curProcess = Process.GetCurrentProcess())
   using (var curModule = curProcess.MainModule)
   {
     return SetWindowsHookEx(WHMOUSELL, proc, GetModuleHandle(curModule.ModuleName), 0);
   }
 }
Beispiel #27
0
 static KeyboardHook()
 {
     _proc = HookCallback;
 }
Beispiel #28
0
 public static extern IntPtr SetWindowsHookEx(int idHook, LowLevelProc lpfn, IntPtr hMod, uint dwThreadId);
Beispiel #29
0
 private static IntPtr SetHook(LowLevelProc proc)
 {
     return(SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0));
 }
Beispiel #30
0
 public LowLevelKeyboardListener()
 {
     proc = HookCallback;
 }
Beispiel #31
0
 public static extern IntPtr SetWindowsHookLowLevel(HookType code,
                                                    LowLevelProc func,
                                                    IntPtr hInstance,
                                                    int threadId);
Beispiel #32
0
 private IntPtr SetHookMouse(LowLevelProc proc)
 {
     using (Process curProcess = Process.GetCurrentProcess())
     using (ProcessModule curModule = curProcess.MainModule) {
         return SetWindowsHookEx(WH_MOUSE_LL, proc,
             GetModuleHandle(curModule.ModuleName), 0);
     }
 }
Beispiel #33
0
 private static extern IntPtr SetWindowsHookEx(
   int hookID,
   LowLevelProc callback,
   IntPtr module,
   uint threadId);
Beispiel #34
0
        /// <summary>
        // Register key capture method.
        /// </summary>
        /// <returns>If successful, a Desktop object, otherwise, null.</returns>
        private static void RegisterKeyboardHookMethod()
        {
            // Get Current Module
                ProcessModule objCurrentModule = Process.GetCurrentProcess().MainModule;

                // Assign callback function each time keyboard process
                objKeyboardProcess = new LowLevelProc(CaptureKey);

                // Assign callback function each time mouse process
                objMouseProcess = new LowLevelProc(CaptureMouseButton);

                // Setting Hook of Keyboard Process for current module
                ptrKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, objKeyboardProcess,
                              GetModuleHandle(objCurrentModule.ModuleName), 0);

                ptrMouseHook = SetWindowsHookEx(WH_MOUSE_LL, objMouseProcess,
                    GetModuleHandle(objCurrentModule.ModuleName), 0);
        }
 public KeyboardHook()
 {
     callback = KeyboardHookCallback;
 }
 private static IntPtr SetKBHook(LowLevelProc proc)
 {
     using (Process curProcess = Process.GetCurrentProcess())
     using (ProcessModule curModule = curProcess.MainModule)
     {
         return SetWindowsHookEx(WH_KEYBOARD_LL, proc,
             GetModuleHandle(curModule.ModuleName), 0);
     }
 }
Beispiel #37
0
 private static extern IntPtr SetWindowsHookEx(int id,
                                               LowLevelProc callback, IntPtr hMod, uint dwThreadId);
 static extern IntPtr SetWindowsHookEx(int idHook, LowLevelProc callback, IntPtr hInstance, uint threadId);
Beispiel #39
0
 public MouseHook()
 {
     callback = MouseHookCallback;
 }
Beispiel #40
0
 public Hook(int hook)
 {
     _hookProc = new LowLevelProc(HookCallback);
     _hookID   = SetHook(_hookProc, hook);
 }
Beispiel #41
0
		static extern IntPtr SetWindowsHookEx(HookType hookType, LowLevelProc lpfn, IntPtr hMod, int dwThreadId);
Beispiel #42
0
 public GlobalServiceBase(Game game)
     : base(game)
 {
     _Proc = HookCallback;
 }
Beispiel #43
0
 private static extern IntPtr SetWindowsHookEx(int id,
     LowLevelProc callback, IntPtr hMod, uint dwThreadId);
Beispiel #44
0
 public MouseHook(string identifier)
 {
     Identifier = identifier;
     _callback  = MouseHookCallback;
 }