Ejemplo n.º 1
0
        private KeyboardHook(KeyboardShortcut shortcut, Action callback)
        {
            _shortcut = shortcut;
            _callback = callback;

            // ReSharper disable once RedundantDelegateCreation
            _proc = new LowLevelKeyboardProc(HookCallback);

            using (var curProcess = Process.GetCurrentProcess())
            {
                using (var curModule = curProcess.MainModule)
                {
                    _hookID = SetWindowsHookEx(WH_KEYBOARD_LL, _proc, GetModuleHandle(curModule.ModuleName), 0);
                }
            }
        }
Ejemplo n.º 2
0
		private KeyboardHook(KeyboardShortcut shortcut, Action callback)
		{
			_shortcut = shortcut;
			_callback = callback;

			// ReSharper disable once RedundantDelegateCreation
			_proc = new LowLevelKeyboardProc(HookCallback);

			using (var curProcess = Process.GetCurrentProcess())
			{
				using (var curModule = curProcess.MainModule)
				{
					_hookID = SetWindowsHookEx(WH_KEYBOARD_LL, _proc, GetModuleHandle(curModule.ModuleName), 0);
				}
			}
		}
Ejemplo n.º 3
0
 public static KeyboardHook Hook(KeyboardShortcut shortcut, Action callback)
 {
     return(new KeyboardHook(shortcut, callback));
 }
		public void EnableKeyboardHook(KeyboardShortcut shortcut)
		{
			if (shortcut.Enabled)
			{
				if (_hooks != null)
					_hooks.Dispose();

				_hooks = KeyboardHook.Hook(shortcut, HandleShortcut);
			}
			else if (_hooks != null)
			{
				_hooks.Dispose();
				_hooks = null;
			}
		}
Ejemplo n.º 5
0
		public static KeyboardHook Hook(KeyboardShortcut shortcut, Action callback)
		{
			return new KeyboardHook(shortcut, callback);
		}