Beispiel #1
0
        public Main()
        {
            Instance = this;

            trayIcon = new Util.TrayIcon();
            PopulateTrayIconDeviceMenu();

            Hook = new KeyboardHook();
            ReAttachKeyboardHook();

            //Hook.RegisterHotKey(ModifierKeys.Control | ModifierKeys.Alt, Keys.F11);
            //Hook.KeyPressed += (sender, e) =>
            //{
            //    try
            //    {
            //        SoundConfig.ToggleDefaultDevice();
            //    }
            //    catch (ConfigurationException ex)
            //    {
            //        Settings.Instance.Show();
            //        MessageBox.Show(ex.Message, "Configuration needed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            //    }
            //};
        }
Beispiel #2
0
        public void ReAttachKeyboardHook()
        {
            try
            {
                Hook.Dispose();
                Hook = new KeyboardHook();

                Keys hotkeyKey;
                ModifierKeys hotkeyModifierKeys;
                if (!String.IsNullOrEmpty(Properties.Settings.Default.HotkeyKey))
                {
                    hotkeyKey = (Keys)Enum.Parse(typeof(Keys), Properties.Settings.Default.HotkeyKey);
                    hotkeyModifierKeys = (ModifierKeys)Enum.Parse(typeof(ModifierKeys), Properties.Settings.Default.HotkeyModifierKeys);
                }
                else
                {
                    hotkeyKey = Keys.F11;
                    hotkeyModifierKeys = Util.ModifierKeys.Alt | Util.ModifierKeys.Control;
                }

                Hook.RegisterHotKey(hotkeyModifierKeys, hotkeyKey);
                Hook.KeyPressed += HandleHotkeyPress;
            }
            catch (Exception ex)
            {
                trayIcon.ShowError(ex.Message);
            }
        }