/// <summary> /// Initializes a new instance of the <see cref="Hotkey"/> class. /// </summary> /// <param name="hotkey"> /// The hotkey in string format. /// </param> public Hotkey(string hotkey) { var hotkeyObj = HotkeyListener.Convert(hotkey); KeyCode = hotkeyObj.KeyCode; Modifiers = hotkeyObj.Modifiers; }
public MainWindow() { Instance = this; FFmpegService.FFmpegDownloader += () => { if (_downloader == null) { _downloader = new FFmpegDownloaderWindow(); _downloader.Closed += (Sender, Args) => _downloader = null; } _downloader.ShowAndFocus(); }; InitializeComponent(); if (DataContext is MainViewModel vm) { vm.Init(!App.CmdOptions.NoPersist, true, !App.CmdOptions.Reset, !App.CmdOptions.NoHotkeys); var listener = new HotkeyListener(); listener.HotkeyReceived += Id => vm.HotKeyManager.ProcessHotkey(Id); ServiceProvider.Get <HotKeyManager>().HotkeyPressed += Service => { switch (Service) { case ServiceName.OpenImageEditor: new ImageEditorWindow().ShowAndFocus(); break; case ServiceName.ShowMainWindow: this.ShowAndFocus(); break; } }; Loaded += (Sender, Args) => { RepositionWindowIfOutside(); vm.ViewLoaded(); }; } if (App.CmdOptions.Tray || ServiceProvider.Get <Settings>().Tray.MinToTrayOnStartup) { Hide(); } Closing += (Sender, Args) => { if (!TryExit()) { Args.Cancel = true; } }; }
/// <summary> /// Overrides the default window message processing /// to detect the registered Hotkeys when pressed. /// </summary> /// <param name="m"></param> protected override void WndProc(ref Message m) { if (m.Msg == WM_HOTKEY) { HotkeyPressed?.Invoke( new SourceApplication( SourceAttributes.GetID(), SourceAttributes.GetHandle(), SourceAttributes.GetName(), SourceAttributes.GetTitle(), SourceAttributes.GetPath(), SourceAttributes.GetSelection()), new HotkeyEventArgs { Hotkey = HotkeyListener.Convert(this.Hotkeys[m.WParam.ToInt32()]), SourceApplication = new SourceApplication( SourceAttributes.GetID(), SourceAttributes.GetHandle(), SourceAttributes.GetName(), SourceAttributes.GetTitle(), SourceAttributes.GetPath(), SourceAttributes.GetSelection()) }); } else { base.WndProc(ref m); } }
public BasicSettingsData(System.Windows.Controls.TextBox processTextfield) { var helper = new WindowInteropHelper(Application.Current.MainWindow); helper.EnsureHandle(); //get a handle witthout the need to show the window hotkeyListener = new Hotkey.HotkeyListener(helper.Handle); hotkeyListener?.RegisterHotKey(HotkeyMod1._Value | HotkeyMod2._Value, HotkeyKey._Value); this.bot = new Bot.Bot(new Input.Keyboard.User32_SendInput_VirtualKeycode()); hotkeyListener.OnHotKeyPressed += () => { if (this.IsBotRunning) { bot.Stop(); } else { bot.Start("\r" + this.HotkeyAction + "\r"); } this.IsBotRunning = !this.IsBotRunning; }; Application.Current.Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted; procChecker = new Timer(checkProcess, null, -1, -1); // init timer, but don`t start processTextfield.IsVisibleChanged += DependentUIElement_IsVisibleChanged; processTextfield.KeyUp += (a, b) => { procChecker.Change(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1)); }; }
public void Setup() { _hotKeyManager.RegisterAll(); _hotkeyActionRegisterer.Register(); var listener = new HotkeyListener(); var hotkeyManager = ServiceProvider.Get <HotKeyManager>(); listener.HotkeyReceived += Id => hotkeyManager.ProcessHotkey(Id); ServiceProvider.Get <HotKeyManager>().HotkeyPressed += Service => { switch (Service) { case ServiceName.OpenImageEditor: new ImageEditorWindow().ShowAndFocus(); break; case ServiceName.ShowMainWindow: MainWindow.Instance.ShowAndFocus(); break; } }; }
public TouchPortalListener(Dispatcher dispatcher) { _client = TouchPortalFactory.CreateClient(this); _dispatcher = dispatcher; _hotkeyListener = new HotkeyListener(); _hotkeyListener.HotkeyPressed += HotkeyListenerOnHotkeyPressed; }
public MainForm() { InitializeComponent(); var hk = new HotkeyListener(); Hotkey unlockHotKey = new Hotkey(Keys.Control | Keys.M); hk.Add(unlockHotKey); hk.HotkeyPressed += HKPressedEvent; }
private void Start_Pause_Listener() { PauseListener = new HotkeyListener(pause_Button, stop_Button); PauseListener.PauseKeyPressed += HotkeyListener_PauseKeyPressed; //subscribe the event to PauseListener_ToggleKeyPressed PauseListener.StopKeyPressed += HotkeyListener_StopKeyPressed; Task.Run(() => { PauseListener.StartListener(); }); }
/// <summary> /// Returns a string conversion containing the Hotkey's /// <see cref="KeyCode"/> and <see cref="Modifiers"/> keys. /// </summary> /// <returns><see cref="String"/></returns> public override string ToString() { if (Modifiers == Keys.None) { return(KeyCode.ToString()); } else { return(HotkeyListener.Convert(this)); } }
public LongScreenWindow(double left, double top, double width, double height) { InitializeComponent(); this.Left = left - m_thickness; this.Top = top - m_thickness; this.Width = width + m_thickness * 2; this.Height = height + m_thickness * 2; CommandManager.RegisterClassInputBinding(typeof(LongScreenWindow), new KeyBinding(ApplicationCommands.Close, new KeyGesture(Key.Escape))); CommandManager.RegisterClassCommandBinding(typeof(LongScreenWindow), new CommandBinding(ApplicationCommands.Close, CloseCommand_Executed)); //Procs.HotkeyListener.Instance = this; HotkeyListener.SetHotKeyHandle(this, Keys.F2, Modifiers.None); }
private void btnSaveClose_Click(object sender, EventArgs e) { // Update the default clipping hotkey // to the new user-defined hotkey. MainForm.hotkeyListener.Update ( // Reference the current clipping hotkey for directly updating // the hotkey without a need for restarting your application. ref MainForm.clippingHotkey, // Convert the selected hotkey's text representation // to a Hotkey object and update it. HotkeyListener.Convert(txtClippingHotkey.Text) ); Close(); }
public HotkeyListenerService(IEventBus eventBus, ISettingsService settingsService, HotkeyListener hotkeyListener, ILogService logService) : base(eventBus) { this.hotkeyListener = hotkeyListener; this.settingsService = settingsService; this.logService = logService; var pausedSubscription = new Subscription <PausedEvent>(PausedHandler); SubscribeBus(pausedSubscription); hotkeyListener.HotkeyPressed += OnHotkeyPressed; foreach (var hotkey in settingsService.Settings.Hotkeys.Values.ToList().Where(x => x != null)) { AddHotkey(hotkey); } hotkeyListener.Add(new Hotkey(System.Windows.Forms.Keys.Escape)); }
static void Main(string[] args) { if ((args.Length == 0 || args[0] != "nocheck") && Process.GetProcessesByName("CleverBoard").Length > 1) { Environment.Exit(2); } var basePath = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); Directory.SetCurrentDirectory(basePath); BindingManager = new HotkeyBindingManager(); BindingManager.Load(); HotkeyListener = new HotkeyListener(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Forms.MainForm()); }