Setups system-wide hot keys and provides possibility to react on their events.
Inheritance: IDisposable
Ejemplo n.º 1
0
 private HotkeyHelper()
 {
     _lock = new object();
     _manager = new HotKeyManager();
     _actions = new Dictionary<HotKey, Action>();
     _manager.KeyPressed += Manager_KeyPressed;
 }
Ejemplo n.º 2
0
        public static void Init(ShadowsocksController controller)
        {
            _hotKeyManager = new HotKeyManager();
            _hotKeyManager.KeyPressed += HotKeyManagerPressed;

            HotkeyCallbacks.InitInstance(controller);
        }
Ejemplo n.º 3
0
        public static void SetNewGlobalHotkeyIfChanged(LoadedSettings loadedSettings, LoadedGlobalHotkey loadedGlobalHotkey, HotKeyManager hkManager)
        {
            if (loadedGlobalHotkey == loadedSettings.General.LoadedGlobalHotkey) return;

            UnregisterGlobalHotkey(hkManager, loadedGlobalHotkey);
            RegisterGlobalHotkey(hkManager, loadedSettings.General.LoadedGlobalHotkey);
            loadedGlobalHotkey = loadedSettings.General.LoadedGlobalHotkey;
        }
Ejemplo n.º 4
0
 public static void UnregisterGlobalHotkey(HotKeyManager hkManager, LoadedGlobalHotkey hotkey)
 {
     if (hotkey.SecondModifierKey != ModifierKeys.None)
     {
         hkManager.Unregister(hotkey.Hotkey, hotkey.FirstModifierKey | hotkey.SecondModifierKey);
     }
     else
     {
         hkManager.Unregister(hotkey.Hotkey, hotkey.FirstModifierKey);
     }
 }
Ejemplo n.º 5
0
        public MainForm()
        {
            InitializeComponent();
            try
            {
                _hotKeyManager = new HotKeyManager();
                _hotKeyManager.KeyPressed += HotKeyManagerPressed;
                _hotKeyManager.Register(System.Windows.Input.Key.X, System.Windows.Input.ModifierKeys.Alt);
            }
            catch
            {
                MessageBox.Show("Не удалось зарегистрировать глобальные горячие клавишы! Возможно, приложение уже запущено.", "Ошибка");
                Environment.Exit(-1);
            }

            _basepath = Application.StartupPath + "\\" + "data.bin";

            if (File.Exists(_basepath))
            {
                int _n = int.Parse((Properties.Settings.Default.lastbackup ?? "0").ToString());
                _n = _n < 10 ? _n + 1 : 1;
                File.Copy(_basepath, _basepath + "_" + _n.ToString(), true);
                Properties.Settings.Default.lastbackup = _n.ToString();
                Properties.Settings.Default.Save();
                Data.NoteList = new faNotes(_basepath);
                Data.NoteList.Load();
            }
            else
            {
                var result = MessageBox.Show("База данных не найдена, создать новую?", "TizTaboo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    Data.NoteList = new faNotes(_basepath);
                    Data.NoteList.Add(new faNote("Тест", "test", "https://vk.com", "", faType.Ссылка, false, 0));
                    if (!Data.NoteList.Save())
                    {
                        MessageBox.Show("Ошибка создания базы!");
                        Environment.Exit(-1);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Main Class for RegistryMonitor.
        /// </summary>
        public Form1()
        {
            if (_allowLogging)
            {
                ExceptionlessClient.Default.Register(false);
                ExceptionlessClient.Default.Configuration.SetUserIdentity(Environment.MachineName);
                ExceptionlessClient.Default.Configuration.UseSessions();
            }

            InitializeComponent();

            _loadedSettings = new LoadedSettings();

            LoadMenu();
            _hkManager = new HotKeyManager();
            LoadGlobalHotkey();
            _menuStrip = menuStrip;

            // Gets the location of the systray icon
            _superNotifyIcon = new SuperNotifyIcon {NotifyIcon = Icon};
            _locationOfIcon = _superNotifyIcon.GetLocation();

            _settingsAlreadyRunning = false;
        }
Ejemplo n.º 7
0
 private void okBtn_Click(object sender, EventArgs e)
 {
     HotKeyManager.setHotKeys(hotKeys);
     Close();
 }
Ejemplo n.º 8
0
 private void btnApply_Click(object sender, EventArgs e)
 {
     HotKeyManager.setHotKeys(hotKeys);
     btnApply.Enabled = false;
 }
Ejemplo n.º 9
0
        private void RegisterGlobalHotKeys()
        {
            this.hotKeyManager = new HotKeyManager();
            this.hotKeyManager.Register(Key.MediaNextTrack, ModifierKeys.None);
            this.hotKeyManager.Register(Key.MediaPreviousTrack, ModifierKeys.None);
            this.hotKeyManager.Register(Key.MediaPlayPause, ModifierKeys.None);

            IObservable<Key> keyPressed = Observable.FromEventPattern<KeyPressedEventArgs>(
                    h => this.hotKeyManager.KeyPressed += h,
                    h => this.hotKeyManager.KeyPressed -= h)
                .Select(x => x.EventArgs.HotKey.Key);

            keyPressed.Where(x => x == Key.MediaNextTrack).InvokeCommand(this.shellViewModel, x => x.NextSongCommand);
            keyPressed.Where(x => x == Key.MediaPreviousTrack).InvokeCommand(this.shellViewModel, x => x.PreviousSongCommand);
            keyPressed.Where(x => x == Key.MediaPlayPause).InvokeCommand(this.shellViewModel, x => x.PauseContinueCommand);
        }