public void ReferenceCountingTest(TestMethodRecord tmr) { // // In this test we are observing how the various keyboard hook // classes are interacting with their implementation classes. They // should add references in their constructor and release them when // disposed. The implementation should only be disposed when the ref // count is zero. // KeyboardHookTestImpl testImpl = new KeyboardHookTestImpl(); tmr.RunTest(testImpl.ReferenceCount == 0, "Now references count is 0."); tmr.RunTest(testImpl.Disposed == false, "Not initially disposed."); using (IKeyboardHook hook1 = HookFactory.CreateKeyboardHook(testImpl)) { tmr.RunTest(testImpl.ReferenceCount == 1, "Now references count is 1."); tmr.RunTest(testImpl.Disposed == false, "Not disposed."); using (IKeyboardHookExt hook2 = HookFactory.CreateKeyboardHookExt(testImpl)) { tmr.RunTest(testImpl.ReferenceCount == 2, "Now references count is 2."); tmr.RunTest(testImpl.Disposed == false, "Not disposed."); } tmr.RunTest(testImpl.ReferenceCount == 1, "Now references count is 1."); tmr.RunTest(testImpl.Disposed == false, "Not disposed."); } tmr.RunTest(testImpl.ReferenceCount == 0, "Now references count is 0."); tmr.RunTest(testImpl.Disposed == true, "Disposed."); }
public MainForm() { InitializeComponent(); mouseHook = new MouseHook(); keyboardHook = new KeyboardHook(); }
public Form1() { InitializeComponent(); colorProps = new ColorProperties(); Load += (sender, args) => { txtHexadecimal.DataBindings.Add("Text", colorProps, "ActualColorHex"); txtARBG.DataBindings.Add("Text", colorProps, "ActualColorRGB"); txtColorDiff.DataBindings.Add("Text", colorProps, "ActualColorDiff"); panel2.DataBindings.Add("BackColor", colorProps, "ActualColor"); Location = new Point(SystemInformation.WorkingArea.Width - Width - 20, SystemInformation.WorkingArea.Height - Height - 50); HookManager.MouseMove += HookManagerMouseMove; hook = KeyboardHooks.Create(); hook.KeyPressed += HandleHootkey; hook.RegisterHotKey(ColorFinder.ModifierKeys.Control, Keys.D); hook.RegisterHotKey(ColorFinder.ModifierKeys.Control | ColorFinder.ModifierKeys.Shift, Keys.D); }; Application.ApplicationExit += (sender, args) => { hook.Dispose(); try { niColorFinder.Visible = false; niColorFinder.Dispose(); } catch (Exception) { niColorFinder = null; } }; }
public Form1() { InitializeComponent(); colorProps = new ColorProperties(); Load += (sender, args) => { txtHexadecimal.DataBindings.Add("Text", colorProps, "ActualColorHex"); txtARBG.DataBindings.Add("Text", colorProps, "ActualColorRGB"); txtColorDiff.DataBindings.Add("Text", colorProps, "ActualColorDiff"); panel2.DataBindings.Add("BackColor", colorProps, "ActualColor"); Location = new Point(SystemInformation.WorkingArea.Width - Width - 20, SystemInformation.WorkingArea.Height - Height - 50); HookManager.MouseMove += HookManagerMouseMove; hook = KeyboardHooks.Create(); hook.KeyPressed += HandleHootkey; hook.RegisterHotKey(ColorFinder.ModifierKeys.Control, Keys.D); hook.RegisterHotKey(ColorFinder.ModifierKeys.Control | ColorFinder.ModifierKeys.Shift, Keys.D); }; Application.ApplicationExit += (sender, args) => { hook.Dispose(); try { niColorFinder.Visible = false; niColorFinder.Dispose(); } catch (Exception) { niColorFinder = null; } }; }
private static void SetupShortcut(IKeyboardHook hook, string shortcutId, string shortcutKeys, ShortcutPressed action) { if (string.IsNullOrEmpty(shortcutKeys)) { hook.UnregisterGlobalShortcut(shortcutId); return; } var keyPress = KeyExtensions.ToKeyPress(shortcutKeys); try { hook.RegisterGlobalShortcut(shortcutId, keyPress.Modifier, keyPress.Key); } catch (Exception e) { MessageBox.Show( Application.Current.MainWindow, string.Format("Could not register global shortcut: {0}", e.Message), "WARNING"); return; } if (hook[shortcutId] == null) { hook[shortcutId] += action; } }
public static void Main() { // Manual loading /*IMouseHook mouseHook = new Core.Windows.Mouse.MouseHook(); * // IMouseHook mouseHook = new Core.Windows.Mouse.RawMouseHook(); * IKeyboardHook keyboardHook = new Core.Windows.Keyboard.KeyboardHook(); * IMessageLoop loop = new Core.Windows.MessageLoop.MessageLoop();*/ // Dynamic loading IHook[] hooks = IHook .Load(Environment.CurrentDirectory) // Load all hooks from current directory's DLLs .Where(x => x.CanBeInstalled) // Select only those hooks that are supported by the current OS .Where(x => x.CanPreventDefault) // We're interested in hooks that can prevent default event actions .ToArray(); IMouseHook mouseHook = hooks.OfType <IMouseHook>().First(); IKeyboardHook keyboardHook = hooks.OfType <IKeyboardHook>().First(); IMessageLoop loop = IMessageLoop.Load(Environment.CurrentDirectory).First(x => x.CanBeRunned); CancellationTokenSource source = new CancellationTokenSource(); loop.OnEvent += Log; // Stop message loop on Ctrl + Shift + S keyboardHook.OnEvent += (_, e) => { if (e.Key.HasFlags(Keys.Control, Keys.Shift, Keys.S)) { source.Cancel(); } }; // Disable 'M' keyboardHook.OnEvent += (_, e) => { if (e.CanPreventDefault && e.Key.HasFlag(Keys.M)) { e.PreventDefault(); } }; // Disable middle mouse button mouseHook.OnEvent += (_, e) => { if (e.CanPreventDefault && e.MouseEventType == MouseEventType.Key && e.Key == MouseButtons.Middle) { e.PreventDefault(); } }; Console.WriteLine("Hook!"); Console.WriteLine("Press CTRL + SHIFT + S to stop!"); loop.Run(source.Token, mouseHook, keyboardHook); Console.Write("Press any key to exit..."); Console.ReadKey(true); }
public KeyboardWatcher() { _hook = Hook.Instance; _hook.KeyUp += _hook_KeyUp; _hook.KeyDown += _hook_KeyDown; _hook.StartHook(); }
private void App_OnStartup(object sender, StartupEventArgs e) { EnsureFolderExists(GetShortcutsFolder()); _shortcutsFolderState.Update(); _keyboardHook = new WindowsKeyboardHook(); _menuWindow = new MenuWindow(GetShortcuts(GetShortcutsFolder())); RegisterHotKeys(); }
public void InstallHookTests(TestMethodRecord tmr) { using (IKeyboardHook kHook = HookFactory.CreateKeyboardHook()) { TestInstallHook(tmr, kHook, "IKeyboardHook"); } using (IKeyboardHookExt kHookExt = HookFactory.CreateKeyboardHookExt()) { TestInstallHook(tmr, kHookExt, "IKeyboardHookExt"); } }
public void CreateKeyboardHookTests(TestMethodRecord tmr) { using (IKeyboardHook hook = HookFactory.CreateKeyboardHook()) { tmr.RunTest(hook != null, "IKeyboardHook created successfully with default options."); } using (IKeyboardHookExt hookExt = HookFactory.CreateKeyboardHookExt()) { tmr.RunTest(hookExt != null, "IKeyboardHookExt created successfully with default options."); } }
public SymbolWindow(SymbolViewModel viewModel, IMouseHook mouseHook, IKeyboardHook keyboardHook) { InitializeComponent(); _viewModel = viewModel; DataContext = _viewModel; _mouseHook = mouseHook; _mouseHook.MouseMove += mouseHook_MouseMove; _mouseHook.MouseDown += mouseHook_MouseDown; _keyboardHook = keyboardHook; _keyboardHook.KeyPress += keyboardHook_KeyPress; }
public DecayGaugeForm() { InitializeComponent(); Reset(); _timer.Start(); _mouseHook = new WindowsMouseHook(); _mouseHook.InstallHook(); _mouseHook.Activity += new EventHandler <MouseEvent>(_mouseHook_Activity); _keyboardHook = new WindowsKeyboardHook(); _keyboardHook.InstallHook(); _keyboardHook.KeyActivity += new EventHandler <KeyEvent>(_keyboardHook_KeyActivity); }
public MainWindow() { InitializeComponent(); User = UserClass.GetInstance(); Settings = SettingsClass.GetInstance(); Loger = new LogerClass(); KeyboardActivity.SetLog(Loger.LogKeyItems); MouseActivity.SetLog(Loger.LogMouseItems); KeyboardHook = new KeyboardHookClass(Loger); MouseHookClass = new MouseHookClass(Loger); Statistic = new StatisticClass(Loger); Worker = new WorkerClass(User, Loger); RemoteServer = new RemoteServerClass(); CurrentWorkFlow = WorkFlowClass.GetWorkFlow(TypeOfWorkFlow.Custom, Convert.ToInt32(Settings.PomodorSize)); PrimePanel.DataContext = Statistic.CommonPrimeWindowProperty; LeftTimeIndicator.DataContext = CurrentWorkFlow; KeysActivityIndicator.DataContext = CurrentWorkFlow; MouseActivityIndicator.DataContext = CurrentWorkFlow; KeyboardHook.StartCapture(); MouseHookClass.StartCapture(); }
private void BindHotKey() { hook = KeyboardHooks.Create(); hook.KeyPressed += hook_KeyPressed; hook.RegisterHotKey(options.ShortcutModifiers, options.ShortcutKey); }
private void BindHotKey() { hook = KeyboardHooks.Create(); hook.KeyPressed += hook_KeyPressed; hook.RegisterHotKey(options.ShortcutModifiers, options.ShortcutKey); }
public KeyTracker(IKeyboardHook keyboardHook) { _keyboardHook = keyboardHook; }
public KeyTracker() { _keyboardHook = new KeyboardHook(); _keyboardHook.KeyDown += OnKeyDown; _keyboardHook.KeyUp += OnKeyUp; }