/* Constructor */ public MainForm() { InitializeComponent(); // Setup global keyboard hook m_GlobalKeyboardHook = new GlobalKeyboardHook(); m_GlobalKeyboardHook.KeyboardPressed += OnKeyPressed; // Setup global mouse hook m_GlobalMouseHook = new GlobalMouseHook(); m_GlobalMouseHook.MouseEvent += OnMouseEvent; // Create macro player m_MacroPlayer = new MacroPlayer(); m_MacroPlayer.Loop = true; m_MacroPlayer.RecordShortcut = true; m_MacroPlayer.PropertyChanged += MacroPlayer_PropertyChanged; // Create remapper m_Remapper = new Remapper(); // Create status checker m_StatusChecker = new StatusChecker(); // Set control mode SetControlMode(ControlMode.Macro); // Create save/load helper m_SaveLoadHelper = new SaveLoadHelper(this, m_MacroPlayer); m_SaveLoadHelper.PropertyChanged += SaveLoadHelper_PropertyChanged; // Initialize interceptor InitInterceptor(); }
private void btnMouseHook_Click(object sender, EventArgs e) { //Let's check if the globablMouseHook is instantiated. if (globalMouseHook == null) { //If it is not created, we instantiate it and subscribe to the available events. globalMouseHook = new GlobalMouseHook(); globalMouseHook.OnButtonDown += GlobalMouseHook_OnButtonDown; globalMouseHook.OnButtonUp += GlobalMouseHook_OnButtonUp; globalMouseHook.OnMouseMove += GlobalMouseHook_OnMouseMove; globalMouseHook.OnMouseWheelScroll += GlobalMouseHook_OnMouseWheelScroll; //Let's also change the text of the button to let the user know that he or she can remove the mouse hook btnMouseHook.Text = REMOVE_MOUSE_HOOK; } else { //If there's already an instance of globalMouseHook, we have to destroy it. globalMouseHook.Dispose(); globalMouseHook = null; //Probably not needed but just to be sure. //Set the text of the button back to the original prompt. btnMouseHook.Text = INSTALL_MOUSE_HOOK; } }
/// <summary> /// Setup Global Hooks /// </summary> private void SetupInputHook() { globalKeyboardHook = new GlobalKeyboardHook(); globalKeyboardHook.KeyboardPressed += OnKeyPressed; globalMouseHook = new GlobalMouseHook(); globalMouseHook.Start(); globalMouseHook.MouseAction += OnMouseAction; }
//The built in GC doesn't know that there is a System Hook installed. We must handle the disposal ourselves when this instance of the class is disposed. public void Dispose() { singleton = null; //Set the value of the singleton to nothing as we are disposing this instance. _globalMouseHook?.Dispose(); //We also need to dispose of the GlobalMouseHook instance that we created. OnButtonDown = null; OnButtonUp = null; OnMouseMove = null; OnMouseWheelScroll = null; }
private void EnableDynamic() { App.Current.Dispatcher.Invoke(() => { keyboardHook.StartHook(); mouseHook = new GlobalMouseHook(); mouseHook.DoubleClick += OnMouseDoubleClicked; SendKeys.Flush(); }); }
protected override void InitializeCore() { // get the theme from the current application var theme = ThemeManager.DetectAppStyle(Application.Current); // now set the Green accent and dark theme ThemeManager.ChangeAppStyle(Application.Current, ThemeManager.GetAccent(AppConfig.AccentColor), ThemeManager.GetAppTheme(AppConfig.AppTheme)); _explorerCleaner = new ExplorerCleaner(AppConfig); _explorerCleaner.Cleaned += (sender, args) => OnCleaned(args); _actionExecuter = new ActionExecuter <ExplorerWindowCleanerClientOperator>(new ExplorerWindowCleanerClientOperator(this, _explorerCleaner)); DisposableCollection.Add(_actionExecuter); ResetBackgroundWorker(AppConfig.Interval, new BackgroundAction[] { new CleanerAction(this) }); if (AppConfig.IsMouseHook) { RestoreClipboardHistories(); MonitoringClipboard(); CreateShortcutContextMenu(); CreateClipboardContextMenu(); _globalMouseHook = new GlobalMouseHook(); _globalMouseHook.MouseHooked += (sender, args) => { if (args.MouseButton == MouseButtons.Left) { _contextMenuClipboardHistories.Close(ToolStripDropDownCloseReason.AppFocusChange); _contextMenuShortcuts.Close(ToolStripDropDownCloseReason.AppFocusChange); } if (args.IsDoubleClick) { if (args.MouseButton == MouseButtons.Right) { _contextMenuClipboardHistories.Tag = GetForegroundWindow(); _contextMenuClipboardHistories.Show(args.Point); } else if (args.MouseButton == MouseButtons.Left && args.IsDesktop) { _contextMenuShortcuts.Show(args.Point); Debug.WriteLine($"Show Shortcut Menu. {args.Point}"); } Debug.WriteLine("DoubleClick Mouse."); } }; } }
static void Main(string[] args) { //Make sure to instantiate the hook itself on the main thread or it wouldn't work. globalKeyHook = new GlobalKeyHook(); globalMouseHook = new GlobalMouseHook(); globalKeyHook.OnKeyDown += GlobalKeyHook_OnKeyDown; globalKeyHook.OnKeyPressed += GlobalKeyHook_OnKeyPressed; globalKeyHook.OnKeyUp += GlobalKeyHook_OnKeyUp; globalMouseHook.OnButtonDown += GlobalMouseHook_OnButtonDown; Thread WaitingThread = new Thread(new ThreadStart(RealMain)); //Create a new thread which will be where the actual tasks will be performed. WaitingThread.Start(); //Start the thread. MessagePump.WaitForMessages(); //Wait for messages from the message pump }
private void ghook_KeyUp(object sender, KeyEventArgs e) { if (this.ContainsFocus) { if (e.KeyData.ToString().ToUpper().IndexOf("LControlKey".ToUpper()) >= 0) { if (globalMouseHook != null) { this.Invoke(new Action(delegate { globalMouseHook.OnMouseWheelScroll -= GlobalMouseHook_OnMouseWheelScroll; globalMouseHook.Dispose(); globalMouseHook = null; })); } } } }
public void ghook_KeyDown(object sender, KeyEventArgs e) { if (this.ContainsFocus) { if (e.KeyData == (Keys.Control | Keys.P)) { this.Invoke(new Action(delegate { br.Print(); })); } if (e.KeyData == (Keys.LControlKey)) { this.Invoke(new Action(delegate { if (globalMouseHook == null) { globalMouseHook = new GlobalMouseHook(); globalMouseHook.OnMouseWheelScroll += GlobalMouseHook_OnMouseWheelScroll; } })); } } }
public void ghook_KeyDown(object sender, KeyEventArgs e) { if (this.ContainsFocus) { if (e.KeyData == (Keys.Alt | Keys.D5)) { this.Invoke(new Action(delegate { url = Interaction.InputBox("Url Girisi", "Url", "", 0, 0); siteisim = Interaction.InputBox("Site isim", "Isim", "", 0, 0); br.Load(url); File.WriteAllText(dosya, url + Environment.NewLine + siteisim); })); } if (e.KeyData == (Keys.F2)) { Ayar a = new Ayar(); if (a.Created) { a.Activate(); } else { a.Show(); } } if (e.KeyData == (Keys.F1)) { pr = new AboutBox1(); if (pr.Created) { pr.Activate(); } else { pr.Show(); } } if (e.KeyData == (Keys.Alt | Keys.D9)) { this.Invoke(new Action(delegate { try { AutoUpdater.Mandatory = true; AutoUpdater.Start("http://localhost/C/deneme.xml"); } catch (Exception ex) { MessageBox.Show("Sunucuya bağlanılamıyor"); } })); } if (e.KeyData == (Keys.Control | Keys.P)) { this.Invoke(new Action(delegate { br.Print(); })); } if (e.KeyData == (Keys.LControlKey)) { this.Invoke(new Action(delegate { if (globalMouseHook == null) { globalMouseHook = new GlobalMouseHook(); globalMouseHook.OnMouseWheelScroll += GlobalMouseHook_OnMouseWheelScroll; } })); } } }