コード例 #1
0
        private void OnHotkeyBoxPreviewKeyDown(object _, KeyEventArgs e)
        {
            e.Handled = true;

            if (recording)
            {
                if (e.Key == Key.Escape)
                {
                    recording            = false;
                    DoneButton.IsEnabled = true;
                    currentHotkeys       = newHotkeys.ToArray();
                    setHotkey(currentHotkeys);

                    newHotkeys.Clear();
                    return;
                }

                var key = KeyInterop.VirtualKeyFromKey(e.Key);

                if (!newHotkeys.Contains(key))
                {
                    newHotkeys.Add(key);
                }

                HotkeyBox.Text = HotkeyUtility.FormatHotkeys(newHotkeys.ToArray());
            }
        }
コード例 #2
0
        public MainWindow()
        {
            InitializeComponent();

            MouseDown += (_, e) => { if (e.ChangedButton == MouseButton.Left)
                                     {
                                         DragMove();
                                     }
            };
            TrayIcon.TrayMouseDoubleClick += OnTrayDoubleClick;

            foreach (var device in deviceEnumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active))
            {
                InputSelect.Items.Add(device);
            }

            InputSelect.SelectionChanged += OnInputSelectSelectionChanged;

            if (config.KeyExists("SoundOnUnmute"))
            {
                PlaySoundsButton.IsChecked = Convert.ToBoolean(config.Read("SoundOnUnmute"));
            }

            if (config.KeyExists("KeyCombo"))
            {
                keyCombo = config.Read("KeyCombo").Split(',').Select(x => int.Parse(x)).ToArray();
            }

            if (config.KeyExists("UnmuteDelay"))
            {
                unmuteMsDelay = int.Parse(config.Read("UnmuteDelay"));
            }

            var id = config.Read("DeviceId");

            InputSelect.SelectedItem = InputSelect.Items.Cast <MMDevice>().FirstOrDefault(x => x.ID == id);

            RunOnStartupButton.IsChecked = StartupManager.WillRunOnStartup;

            SetUnmuteDelayButton.Header = $"Set Unmute Delay: {unmuteMsDelay}ms";
            SetHotkeyButton.Header      = $"Set Hotkey: {HotkeyUtility.FormatHotkeys(keyCombo)}";


            // Keep our mouse smooth by not running in UI thread
            dispatch.BeginInvoke(() =>
            {
                KeyboardHook.Hook();
            });

            KeyboardHook.OnKeyDownEvent += OnKeyDown;
            KeyboardHook.OnKeyUpEvent   += OnKeyUp;
        }
コード例 #3
0
        private void OnSetHotkeyButtonClicked(object _, EventArgs e)
        {
            var dialog = new HotkeySelector(keyCombo, hotkeys =>
            {
                keyCombo = hotkeys;
                config.Write("KeyCombo", String.Join(',', keyCombo));
                SetHotkeyButton.Header = $"Set Hotkey: {HotkeyUtility.FormatHotkeys(keyCombo)}";
            });

            // reset keys so we don't trigger unmute during dialog
            keyCombo = new int[0];
            dialog.ShowDialog();
        }
コード例 #4
0
        private void OnMouseDown(object _, MouseEventArgs e)
        {
            if (recording)
            {
                if (e.XButton1 == MouseButtonState.Pressed && !newHotkeys.Contains(0x05))
                {
                    newHotkeys.Add(0x05);
                }

                if (e.XButton2 == MouseButtonState.Pressed && !newHotkeys.Contains(0x06))
                {
                    newHotkeys.Add(0x06);
                }

                HotkeyBox.Text = HotkeyUtility.FormatHotkeys(newHotkeys.ToArray());
            }
        }
コード例 #5
0
        public HotkeySelector(int[] currentHotkeys, Action <int[]> setHotkey)
        {
            InitializeComponent();

            this.currentHotkeys = currentHotkeys;
            this.setHotkey      = setHotkey;

            MouseDown += (_, e) => { if (e.ChangedButton == MouseButton.Left)
                                     {
                                         DragMove();
                                     }
            };
            MouseDown           += OnMouseDown;
            HotkeyBox.MouseDown += OnMouseDown;

            HotkeyBox.Text = HotkeyUtility.FormatHotkeys(currentHotkeys);
        }