Пример #1
0
        /// <summary>
        /// Event handler when a global hotkey event for this app has been raised. Finds the
        /// preset that corresponds to the hotkey pressed and applies it.
        /// </summary>
        /// <param name="modifierKeyFlags">Modifier keys for the hotkey.</param>
        /// <param name="keycode">Key code for the hotkey.</param>
        private void OnPresetSwitchHotkeyPressed(ushort modifierKeyFlags, ushort keycode)
        {
            // TODO: This kinda sucks because it sorta relies on abusing the interface of PresetToHotkeyMap.
            foreach (KeyValuePair <string, VirtualHotkey> presetHotkeyPair in mPresetToHotkeyMap.GetHotkeyMappings().ToArray())
            {
                // Chop off the MOD_NOREPEAT that is added by HotkeyRegistrar.
                ushort presetModifierKeyFlags =
                    unchecked ((ushort)(presetHotkeyPair.Value.ModifierKeyCode &
                                        (VirtualKeyCodes.MOD_ALT |
                                         VirtualKeyCodes.MOD_CONTROL |
                                         VirtualKeyCodes.MOD_SHIFT |
                                         VirtualKeyCodes.MOD_WIN)));

                ushort presetKeyCode = (unchecked ((ushort)(presetHotkeyPair.Value.KeyCode)));

                if (presetModifierKeyFlags == modifierKeyFlags && presetKeyCode == keycode)
                {
                    DisplayPreset invokedPreset = DisplayPresetCollection.GetDisplayPresetCollection().GetPreset(presetHotkeyPair.Key);

                    if (invokedPreset != null)
                    {
                        SafePresetApplier.ApplyPresetWithRevertCountdown(invokedPreset);
                    }
                    else
                    {
                        throw new Exception("Hotkey pressed for unknown preset.");
                    }

                    break;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Event handler for when an item in the Apply Preset drop down is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ApplyPresetDropDown_ItemClicked(object sender, EventArgs e)
        {
            PresetContextMenuItem presetContextMenuItem = sender as PresetContextMenuItem;

            if (presetContextMenuItem != null)
            {
                SafePresetApplier.ApplyPresetWithRevertCountdown(
                    DisplayPresetCollection.GetDisplayPresetCollection().GetPreset(presetContextMenuItem.PresetName));
            }
        }