Beispiel #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);
                }
            }
        }
		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);
				}
			}
		}
Beispiel #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;
			}
		}
		public static KeyboardHook Hook(KeyboardShortcut shortcut, Action callback)
		{
			return new KeyboardHook(shortcut, callback);
		}