/// <summary> /// This class should be created and passed into Application.Run( ... ) /// </summary> public CustomApplicationContext() { InitializeContext(); // set the keyhooker var keyboardHookManager = new KeyboardHookManager(); keyboardHookManager.Start(); keyboardHookManager.RegisterHotkey(0x60, () => { Debug.WriteLine("NumPad0 detected"); }); keyboardHookManager.RegisterHotkey(NonInvasiveKeyboardHookLibrary.ModifierKeys.Control | NonInvasiveKeyboardHookLibrary.ModifierKeys.Alt, 0x60, () => { Debug.WriteLine("Ctrl+Alt+NumPad0 detected"); }); }
public DarkSwitchApplicationContext() { if (AlreadyRunning()) { Application.Exit(); return; } #region Register hotkey keyBoardManager = new KeyboardHookManager(); keyBoardManager.Start(); keyBoardManager.RegisterHotkey(ModifierKeys.WindowsKey, (int)Keys.OemQuestion, ToggleTheme); #endregion // Save icons lightIcon = Resources.LightIcon; darkIcon = lightIcon.Invert(); var systemUsesLightThemeValue = (int)Registry .GetValue(registryKey, systemUsesLightTheme, 1) != 0; // Initialize Tray Icon var contextMenu = new ContextMenuStrip(); var exit = contextMenu.Items.Add("Exit"); exit.Click += Exit; trayIcon = new NotifyIcon() { Icon = systemUsesLightThemeValue ? lightIcon : darkIcon, ContextMenuStrip = contextMenu, Text = "DarkSwitch", Visible = true, }; trayIcon.MouseClick += new MouseEventHandler(this.Icon_MouseClick); }
private void RegisterHotkey(Hotkey hotkey, Action action) { if (hotkey != null) { KeyboardHookManager.RegisterHotkey(WindowsModifiersToOtherModifiers(hotkey.Modifiers), ResolveKey(hotkey.Key), action); } //Console.WriteLine($"Registered hotkey {hotkey.Modifiers}, {hotkey.Key}, {action}"); }
public Randomizer() { InitializeComponent(); mainBox.SelectedIndex = 0; keyboardHookManager.RegisterHotkey(0x31, NumKeysPressed); keyboardHookManager.RegisterHotkey(0x32, NumKeysPressed); keyboardHookManager.RegisterHotkey(0x33, NumKeysPressed); keyboardHookManager.RegisterHotkey(0x34, NumKeysPressed); keyboardHookManager.RegisterHotkey(0x35, NumKeysPressed); keyboardHookManager.RegisterHotkey(0x36, NumKeysPressed); keyboardHookManager.RegisterHotkey(0x37, NumKeysPressed); keyboardHookManager.RegisterHotkey(0x38, NumKeysPressed); keyboardHookManager.RegisterHotkey(0x39, NumKeysPressed); keyboardHookManager.Start(); }
public PongForm() { InitializeComponent(); this.BackColor = Color.Magenta; this.TransparencyKey = Color.Magenta; scoreLabel = new Label(); scoreLabel.Location = new Point(46 * 10, 4 * 10); this.scoreLabel.Font = new Font("Arial", 16, FontStyle.Bold); this.scoreLabel.BackColor = Color.Transparent; this.Controls.Add(scoreLabel); updateFieldTimer.Tick += new EventHandler(update); this.KeyDown += new KeyEventHandler(getKey); keyboardhook keyHook = new keyboardhook(keyHookEvent); keyboardHookManager.RegisterHotkey(NonInvasiveKeyboardHookLibrary.ModifierKeys.Control, 0x31, () => { Invoke(keyHook); }); Init(); }
private void Form1_Load(object sender, EventArgs e) { mus = new MyUserSettings(); numericX.Value = mus.secondX; numericY.Value = mus.secondY; keyboardHookManager.Start(); keyboardHookManager.RegisterHotkey(NonInvasiveKeyboardHookLibrary.ModifierKeys.Alt, 0x60, () => { Debug.WriteLine("Alt+NumPad0 detected"); //click screen SimMouse.Click(MouseButtons.Left, (int)numericX.Value, (int)numericY.Value); //right minus Thread.Sleep(100); //get active app handle IntPtr handle1 = GetForegroundWindow(); //move app ShowWindow(handle1, 1); MoveWindow(handle1, 200, 200, 500, 500, true); //------------------------------------- //click screen SimMouse.Click(MouseButtons.Left, 1780, 0); //left minus Thread.Sleep(100); //get active app handle IntPtr handle2 = GetForegroundWindow(); //move app ShowWindow(handle2, 1); MoveWindow(handle2, 2120, 363, 500, 500, true); ShowWindowAsync(handle1, 3); ShowWindowAsync(handle2, 3); /* * // left to right * SimMouse.Click(MouseButtons.Left, 1780, 0); * Thread.Sleep(1000); * SimMouse.Act(SimMouse.Action.LeftButtonDown, 1780, 0); * Thread.Sleep(1000); * SimMouse.Act(SimMouse.Action.LeftButtonUp, 1780, 200); * Thread.Sleep(1000); * SimMouse.Act(SimMouse.Action.LeftButtonDown, 1780, 200); * Thread.Sleep(1000); * SimMouse.Act(SimMouse.Action.LeftButtonUp, 2780, 200); * Thread.Sleep(1000); * SimMouse.Click(MouseButtons.Left, 3057, 163); * Thread.Sleep(1000); * * //right to left * SimMouse.Act(SimMouse.Action.LeftButtonDown, 3057, 163); * Thread.Sleep(100); * SimMouse.Act(SimMouse.Action.LeftButtonUp, 3057, 363); * Thread.Sleep(100); * SimMouse.Act(SimMouse.Action.LeftButtonDown, 3057, 363); * Thread.Sleep(100); * SimMouse.Act(SimMouse.Action.LeftButtonUp, 1780, 363); */ }); notifyIcon1.Visible = true; timer1.Stop(); this.Hide(); }