예제 #1
0
 /// <summary>
 /// Unregisters a hotkey
 /// </summary>
 /// <returns>True if successful, else false</returns>
 public bool Unregister(Hotkey hotkey)
 {
     bool result = false;
     Hotkey hotKey;
     if (RegisteredHotkeys.TryRemove(hotkey.KeyId, out hotKey))
     {
         result = User32.UnregisterHotKey(IntPtr.Zero, hotkey.KeyId);
     }
     return result;
 }
예제 #2
0
        /// <summary>
        /// Registers a hotkey
        /// </summary>
        /// <returns>True if successful, else false</returns>
        public bool Register(Hotkey hotkey)
        {
            bool result = User32.RegisterHotKey(IntPtr.Zero, hotkey.KeyId, (UInt32)hotkey.KeyModifiers, (UInt32)hotkey.VirtualKeyCode);
            if (result)
                result = RegisteredHotkeys.TryAdd(hotkey.KeyId, hotkey);

            if (isPaused)
                User32.UnregisterHotKey(IntPtr.Zero, hotkey.KeyId);

            return result;
        }
예제 #3
0
 /// <summary>
 /// </summary>
 /// <returns>True if the given hotkey can be registered, else false</returns>
 public bool CanRegister(Hotkey hotkey)
 {
     bool result;
     if (this.IsRegistered(hotkey))
     {
         // Can't register a hotkey that is already registered
         result = false;
     }
     else
     {
         result = User32.RegisterHotKey(IntPtr.Zero, hotkey.KeyId, (UInt32)hotkey.KeyModifiers, (UInt32)hotkey.VirtualKeyCode);
         User32.UnregisterHotKey(IntPtr.Zero, hotkey.KeyId);
     }
     return result;
 }
예제 #4
0
 /// <summary>
 /// </summary>
 /// <returns>True if the given hotkey has already been registered, else false</returns>
 public bool IsRegistered(Hotkey hotkey)
 {
     return(this.RegisteredHotkeys.ContainsKey(hotkey.KeyId));
 }
예제 #5
0
        /// <summary>
        /// Initializes all hotkeys
        /// </summary>
        public void InitializeHotkeys()
        {
            // Initialize as blank at first
            this.ToggleWorldBossTimerHotkey = new Hotkey(Key.None, KeyModifier.None);
            this.ToggleMetaEventTimerHotkey = new Hotkey(Key.None, KeyModifier.None);
            this.ToggleDungeonsTrackerHotkey = new Hotkey(Key.None, KeyModifier.None);
            this.ToggleDungeonTimerHotkey = new Hotkey(Key.None, KeyModifier.None);
            this.TogglePriceTrackerHotkey = new Hotkey(Key.None, KeyModifier.None);
            this.ToggleWvWTrackerHotkey = new Hotkey(Key.None, KeyModifier.None);
            this.ToggleZoneAssistantHotkey = new Hotkey(Key.None, KeyModifier.None);
            this.ToggleTaskTrackerHotkey = new Hotkey(Key.None, KeyModifier.None);
            this.ToggleTeamspeakTrackerHotkey = new Hotkey(Key.None, KeyModifier.None);
            this.ToggleWebBrowserHotkey = new Hotkey(Key.None, KeyModifier.None);
            this.ToggleInteractiveWindowsHotkey = new Hotkey(Key.None, KeyModifier.None);
            this.ToggleAllWindowsHotkey = new Hotkey(Key.None, KeyModifier.None);
            this.ToggleNotificationWindowBordersHotkey = new Hotkey(Key.None, KeyModifier.None);
            this.ToggleAutoFadeBordersHotkey = new Hotkey(Key.None, KeyModifier.None);
            this.ToggleOverlayMenuIconHotkey = new Hotkey(Key.None, KeyModifier.None);
            this.ToggleMapHotkey = new Hotkey(Key.None, KeyModifier.None);
            this.ToggleDayNightTimerHotkey = new Hotkey(Key.None, KeyModifier.None);

            // Try to load the hotkeys from user settings
            if (!string.IsNullOrEmpty(Properties.Settings.Default.Hotkeys))
            {
                logger.Debug("Loading hotkeys");
                try
                {
                    var loadedHotkeys = JsonConvert.DeserializeObject<HotkeySettingsViewModel>(Properties.Settings.Default.Hotkeys);
                    if (loadedHotkeys != null)
                    {
                        if (loadedHotkeys.ToggleAllWindowsHotkey != null)
                            this.ToggleAllWindowsHotkey = loadedHotkeys.ToggleAllWindowsHotkey;

                        if (loadedHotkeys.ToggleInteractiveWindowsHotkey != null)
                            this.ToggleInteractiveWindowsHotkey = loadedHotkeys.ToggleInteractiveWindowsHotkey;

                        if (loadedHotkeys.ToggleNotificationWindowBordersHotkey != null)
                            this.ToggleNotificationWindowBordersHotkey = loadedHotkeys.ToggleNotificationWindowBordersHotkey;

                        if (loadedHotkeys.ToggleAutoFadeBordersHotkey != null)
                            this.ToggleAutoFadeBordersHotkey = loadedHotkeys.ToggleAutoFadeBordersHotkey;

                        if (loadedHotkeys.ToggleOverlayMenuIconHotkey != null)
                            this.ToggleOverlayMenuIconHotkey = loadedHotkeys.ToggleOverlayMenuIconHotkey;

                        if (loadedHotkeys.ToggleWorldBossTimerHotkey != null)
                            this.ToggleWorldBossTimerHotkey = loadedHotkeys.ToggleWorldBossTimerHotkey;

                        if (loadedHotkeys.ToggleMetaEventTimerHotkey != null)
                            this.ToggleMetaEventTimerHotkey = loadedHotkeys.ToggleMetaEventTimerHotkey;

                        if (loadedHotkeys.ToggleDungeonsTrackerHotkey != null)
                            this.ToggleDungeonsTrackerHotkey = loadedHotkeys.ToggleDungeonsTrackerHotkey;

                        if (loadedHotkeys.ToggleDungeonTimerHotkey != null)
                            this.ToggleDungeonTimerHotkey = loadedHotkeys.ToggleDungeonTimerHotkey;

                        if (loadedHotkeys.TogglePriceTrackerHotkey != null)
                            this.TogglePriceTrackerHotkey = loadedHotkeys.TogglePriceTrackerHotkey;

                        if (loadedHotkeys.ToggleWvWTrackerHotkey != null)
                            this.ToggleWvWTrackerHotkey = loadedHotkeys.ToggleWvWTrackerHotkey;

                        if (loadedHotkeys.ToggleZoneAssistantHotkey != null)
                            this.ToggleZoneAssistantHotkey = loadedHotkeys.ToggleZoneAssistantHotkey;

                        if (loadedHotkeys.ToggleTaskTrackerHotkey != null)
                            this.ToggleTaskTrackerHotkey = loadedHotkeys.ToggleTaskTrackerHotkey;

                        if (loadedHotkeys.ToggleTeamspeakTrackerHotkey != null)
                            this.ToggleTeamspeakTrackerHotkey = loadedHotkeys.ToggleTeamspeakTrackerHotkey;

                        if (loadedHotkeys.ToggleWebBrowserHotkey != null)
                            this.ToggleWebBrowserHotkey = loadedHotkeys.ToggleWebBrowserHotkey;

                        if (loadedHotkeys.ToggleMapHotkey != null)
                            this.ToggleMapHotkey = loadedHotkeys.ToggleMapHotkey;

                        if (loadedHotkeys.ToggleDayNightTimerHotkey != null)
                            this.ToggleDayNightTimerHotkey = loadedHotkeys.ToggleDayNightTimerHotkey;
                    }
                    else
                    {
                        logger.Warn("Unable to load all user hotkeys!");
                    }
                }
                catch (Exception ex)
                {
                    logger.Warn("Unable to load user hotkeys! Exception: ", ex);
                }
            }

            // Register for the pause/resume commands
            HotkeyCommands.PauseHotkeys.RegisterCommand(new DelegateCommand(this.GlobalHotkeyManager.PauseHotkeys));
            HotkeyCommands.ResumeHotkeys.RegisterCommand(new DelegateCommand(this.GlobalHotkeyManager.ResumeHotkeys));

            // Wire the hotkeys up
            this.ToggleAllWindowsHotkey.Pressed += (o, e) => HotkeyCommands.ToggleAllWindowsCommand.Execute(null);
            this.ToggleInteractiveWindowsHotkey.Pressed += (o, e) => HotkeyCommands.ToggleInteractiveWindowsCommand.Execute(null);
            this.ToggleNotificationWindowBordersHotkey.Pressed += (o, e) => HotkeyCommands.ToggleNotificationWindowBordersCommand.Execute(null);
            this.ToggleAutoFadeBordersHotkey.Pressed += (o, e) => HotkeyCommands.ToggleAutoFadeBordersCommand.Execute(null);
            this.ToggleOverlayMenuIconHotkey.Pressed += (o, e) => HotkeyCommands.ToggleOverlayMenuIconCommand.Execute(null);
            this.ToggleWorldBossTimerHotkey.Pressed += (o, e) => HotkeyCommands.ToggleWorldBossTimersCommand.Execute(null);
            this.ToggleMetaEventTimerHotkey.Pressed += (e, r) => HotkeyCommands.ToggleMetaEventTimersCommand.Execute(null);
            this.ToggleDungeonsTrackerHotkey.Pressed += (o, e) => HotkeyCommands.ToggleDungeonsTrackerCommand.Execute(null);
            this.ToggleDungeonTimerHotkey.Pressed += (o, e) => HotkeyCommands.ToggleDungeonTimerCommand.Execute(null);
            this.TogglePriceTrackerHotkey.Pressed += (o, e) => HotkeyCommands.TogglePriceTrackerCommand.Execute(null);
            this.ToggleWvWTrackerHotkey.Pressed += (o, e) => HotkeyCommands.ToggleWvWTrackerCommmand.Execute(null);
            this.ToggleZoneAssistantHotkey.Pressed += (o, e) => HotkeyCommands.ToggleZoneAssistantCommand.Execute(null);
            this.ToggleTaskTrackerHotkey.Pressed += (o, e) => HotkeyCommands.ToggleTaskTrackerCommand.Execute(null);
            this.ToggleTeamspeakTrackerHotkey.Pressed += (o, e) => HotkeyCommands.ToggleTeamspeakOverlayCommand.Execute(null);
            this.ToggleWebBrowserHotkey.Pressed += (o, e) => HotkeyCommands.ToggleWebBrowserCommand.Execute(null);
            this.ToggleMapHotkey.Pressed += (o, e) => HotkeyCommands.ToggleMapOverlayCommand.Execute(null);
            this.ToggleDayNightTimerHotkey.Pressed += (o, e) => HotkeyCommands.ToggleDayNightTimerCommand.Execute(null);

            // Register all hotkeys that are enabled
            if (this.ToggleAllWindowsHotkey.Key != Key.None)
                this.GlobalHotkeyManager.Register(this.ToggleAllWindowsHotkey);
            if (this.ToggleInteractiveWindowsHotkey.Key != Key.None)
                this.GlobalHotkeyManager.Register(this.ToggleInteractiveWindowsHotkey);
            if (this.ToggleNotificationWindowBordersHotkey.Key != Key.None)
                this.GlobalHotkeyManager.Register(this.ToggleNotificationWindowBordersHotkey);
            if (this.ToggleAutoFadeBordersHotkey.Key != Key.None)
                this.GlobalHotkeyManager.Register(this.ToggleAutoFadeBordersHotkey);
            if (this.ToggleOverlayMenuIconHotkey.Key != Key.None)
                this.GlobalHotkeyManager.Register(this.ToggleOverlayMenuIconHotkey);
            if (this.ToggleWorldBossTimerHotkey.Key != Key.None)
                this.GlobalHotkeyManager.Register(this.ToggleWorldBossTimerHotkey);
            if (this.ToggleMetaEventTimerHotkey.Key != Key.None)
                this.GlobalHotkeyManager.Register(this.ToggleMetaEventTimerHotkey);
            if (this.ToggleDungeonsTrackerHotkey.Key != Key.None)
                this.GlobalHotkeyManager.Register(this.ToggleDungeonsTrackerHotkey);
            if (this.ToggleDungeonTimerHotkey.Key != Key.None)
                this.GlobalHotkeyManager.Register(this.ToggleDungeonTimerHotkey);
            if (this.TogglePriceTrackerHotkey.Key != Key.None)
                this.GlobalHotkeyManager.Register(this.TogglePriceTrackerHotkey);
            if (this.ToggleWvWTrackerHotkey.Key != Key.None)
                this.GlobalHotkeyManager.Register(this.ToggleWvWTrackerHotkey);
            if (this.ToggleZoneAssistantHotkey.Key != Key.None)
                this.GlobalHotkeyManager.Register(this.ToggleZoneAssistantHotkey);
            if (this.ToggleZoneAssistantHotkey.Key != Key.None)
                this.GlobalHotkeyManager.Register(this.ToggleZoneAssistantHotkey);
            if (this.ToggleTaskTrackerHotkey.Key != Key.None)
                this.GlobalHotkeyManager.Register(this.ToggleTaskTrackerHotkey);
            if (this.ToggleTeamspeakTrackerHotkey.Key != Key.None)
                this.GlobalHotkeyManager.Register(this.ToggleTeamspeakTrackerHotkey);
            if (this.ToggleWebBrowserHotkey.Key != Key.None)
                this.GlobalHotkeyManager.Register(this.ToggleWebBrowserHotkey);
            if (this.ToggleMapHotkey.Key != Key.None)
                this.GlobalHotkeyManager.Register(this.ToggleMapHotkey);
            if (this.ToggleDayNightTimerHotkey.Key != Key.None)
                this.GlobalHotkeyManager.Register(this.ToggleDayNightTimerHotkey);
        }
예제 #6
0
 /// <summary>
 /// </summary>
 /// <returns>True if the given hotkey has already been registered, else false</returns>
 public bool IsRegistered(Hotkey hotkey)
 {
     return this.RegisteredHotkeys.ContainsKey(hotkey.KeyId);
 }
예제 #7
0
        private void EntryBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (this.HotkeyManager != null)
            {
                if (e.Key != Key.LeftShift
                    && e.Key != Key.RightShift
                    && e.Key != Key.LeftCtrl
                    && e.Key != Key.RightCtrl
                    && e.Key != Key.LeftAlt
                    && e.Key != Key.RightAlt
                    && e.Key != Key.LWin
                    && e.Key != Key.RWin
                    && e.Key != Key.Escape)
                {
                    // Before we go and apply the hotkey, first try it and make sure it will work
                    this.WarningTextBlock.Visibility = Visibility.Hidden;

                    var modifiers = KeyModifier.None;
                    if (e.KeyboardDevice.IsKeyDown(Key.LeftShift) || e.KeyboardDevice.IsKeyDown(Key.RightShift))
                        modifiers |= KeyModifier.Shift;
                    if (e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) || e.KeyboardDevice.IsKeyDown(Key.RightCtrl))
                        modifiers |= KeyModifier.Ctrl;
                    if (e.KeyboardDevice.IsKeyDown(Key.LeftAlt) || e.KeyboardDevice.IsKeyDown(Key.RightAlt))
                        modifiers |= KeyModifier.Alt;
                    if (e.KeyboardDevice.IsKeyDown(Key.LWin) || e.KeyboardDevice.IsKeyDown(Key.RWin))
                        modifiers |= KeyModifier.Win;

                    var newHotkey = new Hotkey(e.Key, modifiers);

                    if (this.HotkeyManager.CanRegister(newHotkey))
                    {
                        // Valid, go ahead and set it
                        this.HotkeyManager.Unregister(this.Hotkey);
                        this.Hotkey.Key = e.Key;
                        this.Hotkey.KeyModifiers = modifiers;
                        this.HotkeyManager.Register(this.Hotkey);
                    }
                    else
                    {
                        // Invalid key combo
                        this.WarningTextBlock.Visibility = Visibility.Visible;
                    }
                }
                else if (e.Key == Key.Escape)
                {
                    // Remove focus
                    this.HiddenBox.Focus();
                }
            }

            this.EntryBox.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
            e.Handled = true;
        }