public Form1() { _currentOptions = new Options(); InitializeComponent(); InitialyzeSpeechEngine(); _myWindows = new List <string>(); RefreshProcessesList(); FetchProfiles(); _ghk = new GlobalHotkey(0x0004, Keys.None, this); System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); System.Reflection.AssemblyName assemblyName = assembly.GetName(); Version version = assemblyName.Version; this.Text += " version : " + version.ToString(); RefreshSettings(); }
//-----------------------------------------------------------SMART GUARD private void RegisterHotkey() { if (ghk != null) { ghk.Unregister(); } /* * Modifiers.NoMod; * Modifiers.Alt; * Modifiers.Ctrl; * Modifiers.Shift; * Modifiers.Win; */ //there Q button var key = (Keys)Enum.Parse(typeof(Keys), "Q"); //hotkeyTextBox.Text.ToUpper()); var mod = Modifiers.Shift; //Modifiers.NoMod; try { ghk = new GlobalHotkey(mod, key, this, true); } catch (GlobalHotkeyException exc) { MessageBox.Show(exc.Message); } }
private HotKeyHelper() { IsInitialized = false; CurrentHotkey = new GlobalHotkey(); IsListening = false; }
/// <summary> /// Removes hotkey and binded command /// </summary> private void HandleKeyBindRemove() { // it was checked if anything is selected // and we know for sure only one item can be selected int globalHotkeyId = Int32.Parse(this.listView1.SelectedItems[0].SubItems[2].Text); GlobalHotkey ghToRemove = null; // we are looking for the gh to delete foreach (GlobalHotkey gh in this.ghList) { if (gh.Id.Equals(globalHotkeyId)) { ghToRemove = gh; } } // then we find it's index in a List, remove it and call Dispose() to unregister int i = 0; while (i < this.ghList.Count) { GlobalHotkey currentGh = this.ghList[i]; if (ghToRemove.Equals(currentGh)) { this.ghList.RemoveAt(i); ghToRemove.Dispose(); break; } i++; } this.listView1.SelectedItems[0].Remove(); }
/// <summary> /// Listen to the given kotkey /// </summary> public void ListenForHotKey(GlobalHotkey globalHotkey) { if (!IsInitialized) { throw new ApplicationException("Hotkey helper is not initialized"); } if (IsListening) { return; } var winFormsKey = (System.Windows.Forms.Keys)KeyInterop.VirtualKeyFromKey(globalHotkey.Key); bool isKeyRegisterd = RegisterHotKey(_windowHandle, HotkeyID, (uint)globalHotkey.Modifiers, (uint)winFormsKey); if (!isKeyRegisterd) { // Unregister hotkey and try again if first attempts fails UnregisterHotKey(IntPtr.Zero, HotkeyID); isKeyRegisterd = RegisterHotKey(_windowHandle, HotkeyID, (uint)globalHotkey.Modifiers, (uint)winFormsKey); if (!isKeyRegisterd) { throw new ApplicationException("The hotkey is already in use"); } } IsListening = true; }
private void RestoreSettings() { _isRestoring = true; // General settings CheckBoxAlwaysOnTop.IsChecked = ClippySettings.Instance.MainWindowAlwaysOnTop; CheckBoxAutosaveWindowLayout.IsChecked = ClippySettings.Instance.SaveWindowLayoutState; CheckBoxAutosaveItems.IsChecked = ClippySettings.Instance.AutoSaveState; CheckBoxTextItemNameFromContent.IsChecked = ClippySettings.Instance.TextItemNameFromContent; CheckBoxShowTrayIcon.IsChecked = ClippySettings.Instance.ShowIconInSystemTray; _currentHotkey = ClippySettings.Instance.GlobalHotkey; TextboxGlobalHotkey.Text = _currentHotkey.ToString(); CheckBoxGlobalHotkey.IsChecked = _currentHotkey.IsActive; // Clipboard file settings CheckBoxUseClipboardFiles.IsChecked = ClippySettings.Instance.UseClipboardFiles; CheckBoxAllowEmptyClipboardFile.IsChecked = ClippySettings.Instance.AllowEmptyClipboardFiles; TextBoxClipboardTextFile.Text = ClippySettings.Instance.ClipboardTextFileName; if (ClippySettings.Instance.UseClipboardFiles) { ValidateFileTextBox(TextBoxClipboardTextFile); } int codepage = ClippySettings.Instance.ClipboardTextFileEncoding; ComboBoxEncoding.SelectedIndex = Array.FindIndex(Encoding.GetEncodings(), enc => enc.CodePage == codepage); _isRestoring = false; }
private void RegisterHotKeys() { m_HotkeyAreaScreenshot = new GlobalHotkey(Program.globalSetting.AreaHotkey); m_HotkeyAreaScreenshot.Pressed += Hk_AreaScreenshot; if (!m_HotkeyAreaScreenshot.GetCanRegister(this)) { Console.WriteLine("Already registered"); } else { m_HotkeyAreaScreenshot.Register(this); } m_HotkeyClipBoard = new GlobalHotkey(Program.globalSetting.ClipboardHotkey); m_HotkeyClipBoard.Pressed += Hk_ClipBoard; if (!m_HotkeyClipBoard.GetCanRegister(this)) { Console.WriteLine("Already registered"); } else { m_HotkeyClipBoard.Register(this); } }
private void Form1_Load(object sender, EventArgs e) { // Load Play Area top = Properties.Settings.Default.top; bot = Properties.Settings.Default.bot; left = Properties.Settings.Default.left; right = Properties.Settings.Default.right; GameEngine.SetPlayableArea(new Rectangle(left, top, right - left, bot - top)); // By moving here, we do not reload the tasklist every time we stop the program with the GHK // Load Tasks string ret = PlayerEngine.ParseTasklist(Properties.Settings.Default.taskList); if (ret != null) { MessageBox.Show(string.Format("Error parsing task list: {0}", ret)); return; } // Set Discount GameEngine.SetHeroDiscount(1.0 - 0.02 * Properties.Settings.Default.dogcog); // Set Hotkey ghk = new GlobalHotkey(GlobalHotkey.Constants.CTRL + GlobalHotkey.Constants.SHIFT, Keys.D, this); if (!ghk.Register()) { throw new Exception("can't register"); } }
public LogoWindow() { InitializeComponent(); ContentRendered += (_, __) => { AddLogLine("Activate Penguintter"); AddLogLine("Registering global hotkey..."); var hotkey = new GlobalHotkey(this); hotkey.Regist(ModifierKeys.Control | ModifierKeys.Alt, Key.T, new EventHandler(ShowUpdateView)); hotkey.Regist(ModifierKeys.Control | ModifierKeys.Alt, Key.L, new EventHandler(ShowLogView)); hotkey.Regist(ModifierKeys.Control | ModifierKeys.Alt, Key.C, new EventHandler(ShowConfigView)); AddLogLine("-> done"); AddLogLine("Initializing cache..."); var app = (App)Application.Current; app.LoadCache(); AddLogLine("-> done"); AddLogLine("Checking " + Config.ConfigFileName + "..."); if (app.LoadConfig()) { AddLogLine("-> Detected"); } else { AddLogLine("-> Not found or Deserialize Error: Apply default configuration"); } AddLogLine("Checking " + Account.AccountFileName + "..."); if (app.LoadAccount()) { AddLogLine("-> Detected: Loaded account data"); } else { AddLogLine("-> Not found or Deserialize Error: Creating and saving new account data..."); if (app.CreateAccount()) { AddLogLine("-> Saved successfully"); } else { AddLogLine("-> FAILED"); AddLogLine("アプリケーションを終了してください"); return; } app.LoadAccount(); AddLogLine("Loaded account data"); } AddLogLine("Start streaming"); Timer.Tick += (___, ____) => { WindowState = WindowState.Minimized; Timer.Stop(); }; Timer.Start(); ((App)Application.Current).StartStream(); }; }
public Switcher(GlobalHotkey switcherHotkey, WindowLister windowLister) { _windowLister = windowLister; BindGlobalHotkey(switcherHotkey); InitializeComponent(); InitializeTrayIcon(); SetupWindowSelection(); HideWindowFromAltTabList(); }
private void Form1_Load(object sender, EventArgs e) { // Set Hotkey ghk = new GlobalHotkey(GlobalHotkey.Constants.CTRL + GlobalHotkey.Constants.SHIFT, Keys.D, this); if (!ghk.Register()) { throw new Exception("can't register"); } }
public Form1() { InitializeComponent(); ghk = new GlobalHotkey(Modifiers.NoMod, Keys.Escape, this); ghk.Register(); Native.SetMonitorEnable(this.Handle, false); this.Shown += (o, e) => this.Hide(); }
// ホットキー登録 private void setHotkey() { try { ghk = new GlobalHotkey(GlobalHotkey.ModifierKeys.Alt, Keys.S); ghk.keyEvent += floatingWindow; } catch (GlobalHotkey.HotkeyRegistrationException) { viewStatus("Hotkey registration failed.", statusType.warning); } }
private void handleNewKeybind(KeyEventArgs e) { // Make new keybind GlobalHotkey hotkey = new GlobalHotkey(KeyModifiers.NOMOD, e.KeyCode, this.ParentForm); Keybinds.addKeybind(new Keybind(hotkey, this.sound)); Keybinds.removeKeybind(this.keybind); this.Keybind.Text = e.KeyCode.ToString(); }
private void window_Closed(object sender, EventArgs e) { clipboardItems.WriteToFile(); StoreFormParams(); Settings.SaveSettings(); showHotKey.Dispose(); showHotKey = null; notifyIcon.Dispose(); notifyIcon = null; }
private void RegisterHotkeys() { ScanScreenshotHotkey = new GlobalHotkey(HotkeyConstants.NOMOD, Settings.Settings.ScanHotkey, this); ScanScreenshotHotkey.Triggered += ScanScreenshotHotkeyTriggered; ScanScreenshotHotkey.Register(); ScanTextboxHotkey = new GlobalHotkey(HotkeyConstants.NOMOD, Settings.Settings.RescanHotkey, this); ScanTextboxHotkey.Triggered += ScanTextBoxHotkeyTriggered; ScanTextboxHotkey.Register(); }
public MainWindow() { InitializeComponent(); HotkeysManager.SetupSystemHook(); GlobalHotkey hotkey1 = new GlobalHotkey(ModifierKeys.Alt, Key.N, Hotkey1); GlobalHotkey hotkey2 = new GlobalHotkey(ModifierKeys.Alt, Key.M, Hotkey2); HotkeysManager.AddHotkey(hotkey1); HotkeysManager.AddHotkey(hotkey2); #region send application to tray System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon(); ni.Icon = new System.Drawing.Icon("image.ico"); ni.Visible = true; ni.Click += delegate(object sender, EventArgs e) { this.Show(); this.WindowState = System.Windows.WindowState.Normal; }; ni.DoubleClick += delegate(object sender, EventArgs e) { this.WindowState = System.Windows.WindowState.Normal; close = true; this.Close(); }; #endregion audioController = new CoreAudioController(); defaultOutput = audioController.DefaultPlaybackDevice; var OutputDevices = audioController.GetPlaybackDevices(DeviceState.Active); foreach (var device in OutputDevices) { dropDownMenu.Items.Add(device.FullName); dropDownMenu2.Items.Add(device.FullName); } data = SaveLoadManager.Load(); if (data != null) { dropDownMenu.Text = data.device1Name; dropDownMenu2.Text = data.device2Name; } AddHotKeys(); }
public void StopListening() { if (HotkeyID != 0) { UnregisterHotKey(_windowHandle, HotkeyID); GlobalDeleteAtom(HotkeyID); HotkeyID = 0; CurrentHotkey = new GlobalHotkey(); IsListening = false; } }
private void TbHotkey_OnPreviewKeyDown(object sender, KeyEventArgs e) { e.Handled = true; tbMsg.Visibility = Visibility.Hidden; //when alt is pressed, the real key should be e.SystemKey Key key = (e.Key == Key.System ? e.SystemKey : e.Key); string text = string.Empty; SpecialKeyState specialKeyState = new GlobalHotkey().CheckModifiers(); if (specialKeyState.AltPressed) { text += "Alt"; } if (specialKeyState.CtrlPressed) { text += string.IsNullOrEmpty(text) ? "Ctrl" : " + Ctrl"; } if (specialKeyState.ShiftPressed) { text += string.IsNullOrEmpty(text) ? "Shift" : " + Shift"; } if (specialKeyState.WinPressed) { text += string.IsNullOrEmpty(text) ? "Win" : " + Win"; } if (string.IsNullOrEmpty(text)) { text += "Ctrl + Alt"; } if (IsKeyACharOrNumber(key)) { text += " + " + key; } else if (key == Key.Space) { text += " + Space"; } else { return; } if (text == tbHotkey.Text) { return; } Dispatcher.DelayInvoke("HotkeyAvailableTest", o => SetHotkey(text), TimeSpan.FromMilliseconds(300)); }
private void RegisterTriggerKey(Keys key, int mod = Constants.NOMOD) { try { mainTrigger = new GlobalHotkey(mod, key, this); mainTrigger.Register(); } catch (GlobalHotkeyException e) { MessageBox.Show(e.Message, "Registration Error"); this.BeginInvoke(new MethodInvoker(Close)); } }
public GlobalHotkeyListener() { InitializeComponent(); this.WindowState = FormWindowState.Minimized; this.Hide(); //Makes it not show up on taskbar this.TopLevel = false; //Makes it not show up under Apps in Task Manager trayIcon = null; //Shows the system tray icon processDetector = null; queryHandler = null; warframeProcess = null; mainTrigger = null; }
/* * Sets the hotkeys using global hotkey objects *Depreciated* */ public void setVolumeHotkeys(GlobalHotkey volumeUp, GlobalHotkey volumeDown) { if (hotkeyVolUp != null) { hotkeyVolUp.Unregister(); } else if (hotkeyVolDown != null) { hotkeyVolDown.Unregister(); } hotkeyVolUp = volumeUp; hotkeyVolDown = volumeDown; hasHotkey = true; }
private void BtnFindControl_MouseUp(object sender, MouseEventArgs e) { var point = ClickOnPointTool.GetCursorPosition(); var hwnd = ClickOnPointTool.WindowFromPoint(new POINT { X = point.X, Y = point.Y }); if (hwnd.ToInt64() > 0) { StringBuilder className = new StringBuilder(256); var nRet = ClickOnPointTool.GetClassName(hwnd, className, className.Capacity); //For Parent IntPtr hWndParent = ClickOnPointTool.GetParent(hwnd); if (hWndParent.ToInt64() > 0) { txtClass.Text = ClickOnPointTool.GetClassNameOfWindow(hWndParent); txtName.Text = ClickOnPointTool.GetCaptionOfWindow(hWndParent); ghk = new GlobalHotkey(GlobalHotkey.ALT, Keys.S, hwnd); ghkMain = new GlobalHotkey(GlobalHotkey.ALT, Keys.S, this.Handle); var isSuccess = ghk.Register(); var isSuccessMain = ghkMain.Register(); //if (isSuccess || isSuccessMain) //MessageBox.Show("Hotkey registered."); if (Configs.Count > 0) { foreach (var config in Configs) { config.WindowClass = txtClass.Text; config.WindowName = txtName.Text; config.WindowHandle = hWndParent; } } // LoadingConfigs = new List<Configuration.Config>() //{ // new Configuration.Config // { // No = 1, Delay = 500, XPos = 439, YPos = 387, ColorName = "ff222222", // WindowClass = txtClass.Text, WindowName =txtName.Text, WindowHandle = hWndParent // } //}; } } Cursor.Current = Cursors.Default; }
void window_Loaded(object sender, RoutedEventArgs e) { WindowInteropHelper wih = new WindowInteropHelper(window); hWndSource = HwndSource.FromHwnd(wih.Handle); clipboardWatcher = new ClipboardWatcher(hWndSource.Handle); clipboardWatcher.OnClipboardChanged += new EventHandler(ClipboardChanged); clipboardWatcher.SetClipboardHandle(); hWndSource.AddHook(clipboardWatcher.ReceiveMessage); showHotKey = new GlobalHotkey(Modifiers.Win, Keys.Oemtilde, window, true); showHotKey.HotkeyPressed += new EventHandler <HotkeyEventArgs>(DoOnShowHotKey); if (Settings.Current.WasClosed) { window.Hide(); } }
/* * Registers the hotkeys assigned to this group with the operating system * and associates them with the programs main window */ public void registerHotkey(IWin32Window window) { if (!hasHotkey && !hotkeyPendingRegistration) { return; } Keys volUpKey = Keys.None; Keys volDownKey = Keys.None; //convert the Keys and Modifiers into a useable form if (volumeUp != "None" && volumeUp != null) { volUpKey = (Keys)Enum.Parse(typeof(Keys), volumeUp); } if (volumeDown != "None" && volumeDown != null) { volDownKey = (Keys)Enum.Parse(typeof(Keys), volumeDown); } Modifiers modifiers = Modifiers.NoMod; foreach (string keyModifier in mods) { modifiers |= (Modifiers)Enum.Parse(typeof(Modifiers), keyModifier); } //create the hotkeys from hotkey data and register them with the system try { if (volumeUp != "None") { hotkeyVolUp = new GlobalHotkey(modifiers, volUpKey, window, true); } if (volumeDown != "None") { hotkeyVolDown = new GlobalHotkey(modifiers, volDownKey, window, true); } hasHotkey = true; hotkeyPendingRegistration = false; } catch (GlobalHotkeyException exc) { MessageBox.Show(exc.Message); } Console.WriteLine(groupName + " HotkeysRegistered"); }
public MacroForm() { InitializeComponent(); GetScale(); mouseHook.MouseMove += mouseHook_MouseMove; mouseHook.MouseDown += mouseHook_MouseDown; mouseHook.MouseUp += mouseHook_MouseUp; mouseHook.MouseWheel += MouseHook_MouseWheel; keyboardHook.KeyDown += keyboardHook_KeyDown; keyboardHook.KeyUp += keyboardHook_KeyUp; keyboardHook.KeyPress += KeyboardHook_KeyPress; ghk = new GlobalHotkey(Constants.ESC, Keys.Escape, this); hotkeymessage = false; foreverloopmessage = false; this.Hidewindow.Checked = true; this.HotkeyActivated.Checked = true; }
private void InitializeKeys() { //? See if you actually need this, makes it to where key presses are detected across all forms, does this include while the app is closed too? //? If the above is true then this will need to have a setting in the options panel this.KeyPreview = true; // GlobalHotkey ghShiftAlt = new GlobalHotkey(VirtualKey.SHIFT + VirtualKey.ALT, Keys.None, this); //ghDivide = new GlobalHotkey(VirtualKey.NOMOD, Keys.Divide, this); //ghMultiply = new GlobalHotkey(VirtualKey.NOMOD, Keys.Multiply, this); //ghNumPad5 = new GlobalHotkey(VirtualKey.NOMOD, Keys.NumPad5, this); if (!ghShiftAlt.Register()) { MessageBox.Show("Hotkey failed to register!"); } }
private void handleNewKeybind(KeyEventArgs e) { // Make new keybind GlobalHotkey hotkey = new GlobalHotkey(KeyModifiers.NOMOD, e.KeyCode, this.ParentForm); string soundName = KeybindName.Text; Sound sound = new Sound(soundName, this.soundPath); Keybind bind = new Keybind(hotkey, sound); Keybinds.addKeybind(bind); SoundKeybind panel = new SoundKeybind(); panel.SetSoundName(sound); panel.SetKeybindText(bind, e.KeyCode.ToString()); SoundKeybinds.Controls.Add(panel); }
private void MainForm_Load(object sender, EventArgs e) { // 热键定义 textBoxStartStop.Value = model.StartStopKey; textBoxRecord.Value = model.RecordKey; hotkey = new GlobalHotkey(Handle); hotkeyIdStartStop = hotkey.RegisterHotkey(textBoxStartStop.Value.Key, textBoxStartStop.Value.Modifiers); hotkeyIdRecord = hotkey.RegisterHotkey(textBoxRecord.Value.Key, textBoxRecord.Value.Modifiers); hotkey.OnHotkey += OnHotkey; // 动作列表 SetListView(); if (listView.Items.Count > 0) { listView.Items[0].Selected = true; } }
// Form, hotkey processing in WndProc public Form1() { hotkey_restart = new GlobalHotkey(GlobalHotkey.Constants.NOMOD, Keys.R, this); hotkey_nextRoom = new GlobalHotkey(GlobalHotkey.Constants.NOMOD, Keys.F2, this); hotkey_lastRoom = new GlobalHotkey(GlobalHotkey.Constants.NOMOD, Keys.F1, this); hotkey_setRoom = new GlobalHotkey(GlobalHotkey.Constants.NOMOD, Keys.F5, this); // Registering hotkeys is done in timer_read_Tick, they will unregister if the game isn't open so they don't interfere in other apps InitializeComponent(); populateRoomList(); // Put GlobalHotkeys as tags on textbox components to make rebinding easier hotkeyHardReset.Tag = hotkey_restart; hotkeyNextRoom.Tag = hotkey_nextRoom; hotkeyPreviousRoom.Tag = hotkey_lastRoom; hotkeySetRoom.Tag = hotkey_setRoom; }
/// <summary> /// Adds the hotkey and binded command /// </summary> private void HandleKeyBindAdd() { int globalHotkeyId; var key = (Keys)Enum.Parse(typeof(Keys), textBoxKey.Text.ToUpper()); // check if mod keys are checked var mod = Modifiers.NoMod; if (this.checkBoxAlt.Checked) { mod = mod | Modifiers.Alt; } if (this.checkBoxCtlr.Checked) { mod = mod | Modifiers.Ctrl; } if (this.checkBoxShift.Checked) { mod = mod | Modifiers.Shift; } if (this.checkBoxWinKey.Checked) { mod = mod | Modifiers.Win; } try { GlobalHotkey gh = new GlobalHotkey(mod, key, this, true); globalHotkeyId = gh.Id; gh.command = this.textBoxCommand.Text; this.ghList.Add(gh); } catch (GlobalHotkeyException e) { MessageBox.Show(e.Message); return; } // when shortcut registered successfully ListViewItem listItem = new ListViewItem(String.Format("{0} {1}", mod, key)); listItem.SubItems.Add(this.textBoxCommand.Text); listItem.SubItems.Add(globalHotkeyId.ToString()); this.listView1.Items.Add(listItem); }
private void RegisterClick(object sender, EventArgs e) { if (ghk != null) ghk.Unregister(); if (string.IsNullOrWhiteSpace(hotkeyTextBox.Text)) { MessageBox.Show(Resources.NoHotkeyErrorMessage); return; } var key = (Keys)Enum.Parse(typeof(Keys), hotkeyTextBox.Text.ToUpper()); var mod = Modifiers.NoMod; if (altCheckBox.Checked) mod |= Modifiers.Alt; if (ctrlCheckBox.Checked) mod |= Modifiers.Ctrl; if (shiftCheckBox.Checked) mod |= Modifiers.Shift; if (winCheckBox.Checked) mod |= Modifiers.Win; try { ghk = new GlobalHotkey(mod, key, this, true); } catch(GlobalHotkeyException exc) { MessageBox.Show(exc.Message); } }
void MainWindow_Loaded(object sender, RoutedEventArgs e) { GlobalHotkey hotkey = new GlobalHotkey(KeyModifier.Control, System.Windows.Forms.Keys.G); hotkey.Pressed += new EventHandler<Common.Controls.Windows.Hotkey.HotkeyEventArgs>(hotkey_Pressed); clipboard = new Common.Controls.Windows.Clipboard(); }
private void initialise_hotkey() { hide_show_hotkey = new GlobalHotkey(0, HIDE_SHOW_HOTKEY, this); history_hotkey = new GlobalHotkey(0, HISTORY_HOTKEY, this); }