예제 #1
0
            // In the three event handlers below we will not mark the event as handled
            // because this is a supplemental operation and we don't want to interfere with
            // the normal keyboard handling.
            private static void OnCharacterReceivedHandler(CoreWindow sender, CharacterReceivedEventArgs args)
            {
                int  viewId = Utilities.GetWindowId();
                bool hit    = s_fHonorShortcuts.TryGetValue(viewId, out var currentHonorShortcuts);

                if (!hit || currentHonorShortcuts)
                {
                    char character = ((char)args.KeyCode);
                    var  buttons   = EqualRange(s_characterForButtons[viewId], character);
                    KeyboardShortcutManagerLocals.RunFirstEnabledButtonCommand(buttons);

                    KeyboardShortcutManagerLocals.LightUpButtons(buttons);
                }
            }
예제 #2
0
            private static void OnKeyDownHandler(CoreWindow sender, KeyEventArgs args)
            {
                s_keyHandlerCount++;

                if (args.Handled)
                {
                    return;
                }

                var key    = args.VirtualKey;
                int viewId = Utilities.GetWindowId();

                bool isControlKeyPressed = (Window.Current.CoreWindow.GetKeyState(Windows.System.VirtualKey.Control) & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
                bool isShiftKeyPressed   = (Window.Current.CoreWindow.GetKeyState(Windows.System.VirtualKey.Shift) & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
                bool isAltKeyPressed     = (Window.Current.CoreWindow.GetKeyState(Windows.System.VirtualKey.Menu) & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;

                // Handle Ctrl + E for DateCalculator
                if ((key == Windows.System.VirtualKey.E) && isControlKeyPressed && !isShiftKeyPressed && !isAltKeyPressed)
                {
                    NavigateModeByShortcut(true, false, false, key, ViewMode.Date);
                    return;
                }

                if (s_ignoreNextEscape.TryGetValue(viewId, out var currentIgnoreNextEscape))
                {
                    if (currentIgnoreNextEscape && key == Windows.System.VirtualKey.Escape)
                    {
                        if (s_keepIgnoringEscape.TryGetValue(viewId, out var currentKeepIgnoringEscape))
                        {
                            if (!currentKeepIgnoringEscape)
                            {
                                HonorEscape();
                            }
                            return;
                        }
                    }
                }

                if (s_fHonorShortcuts.TryGetValue(viewId, out var currentHonorShortcuts))
                {
                    if (currentHonorShortcuts)
                    {
                        var myVirtualKey = key;
                        var lookupMap    = GetCurrentKeyDictionary(isControlKeyPressed, isShiftKeyPressed, isAltKeyPressed);
                        if (lookupMap == null)
                        {
                            return;
                        }

                        var buttons = EqualRange(lookupMap, (MyVirtualKey)myVirtualKey);
                        if (!buttons.Any())
                        {
                            return;
                        }

                        KeyboardShortcutManagerLocals.RunFirstEnabledButtonCommand(buttons);

                        // Ctrl+C and Ctrl+V shifts focus to some button because of which enter doesn't work after copy/paste. So don't shift focus if Ctrl+C or Ctrl+V
                        // is pressed. When drop down is open, pressing escape shifts focus to clear button. So dont's shift focus if drop down is open. Ctrl+Insert is
                        // equivalent to Ctrl+C and Shift+Insert is equivalent to Ctrl+V
                        //var currentIsDropDownOpen = s_IsDropDownOpen.find(viewId);
                        if (!s_IsDropDownOpen.TryGetValue(viewId, out var currentIsDropDownOpen) || !currentIsDropDownOpen)
                        {
                            // Do not Light Up Buttons when Ctrl+C, Ctrl+V, Ctrl+Insert or Shift+Insert is pressed
                            if (!(isControlKeyPressed && (key == Windows.System.VirtualKey.C || key == Windows.System.VirtualKey.V || key == Windows.System.VirtualKey.Insert))
                                & !(isShiftKeyPressed && (key == Windows.System.VirtualKey.Insert)))
                            {
                                KeyboardShortcutManagerLocals.LightUpButtons(buttons);
                            }
                        }
                    }
                }
            }
예제 #3
0
            private static void OnKeyDownHandler(CoreWindow sender, KeyEventArgs args)
            {
                if (args.Handled)
                {
                    return;
                }

                var key    = args.VirtualKey;
                int viewId = Utilities.GetWindowId();

                bool isControlKeyPressed = (Window.Current.CoreWindow.GetKeyState(Windows.System.VirtualKey.Control) & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
                bool isShiftKeyPressed   = (Window.Current.CoreWindow.GetKeyState(Windows.System.VirtualKey.Shift) & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
                bool isAltKeyPressed     = (Window.Current.CoreWindow.GetKeyState(Windows.System.VirtualKey.Menu) & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;

                // Handle Ctrl + E for DateCalculator
                if ((key == Windows.System.VirtualKey.E) && isControlKeyPressed && !isShiftKeyPressed && !isAltKeyPressed)
                {
                    var lookupMap = GetCurrentKeyDictionary(isControlKeyPressed, isShiftKeyPressed, false);
                    if (lookupMap == null)
                    {
                        return;
                    }

                    var buttons      = EqualRange(lookupMap, (MyVirtualKey)key);
                    var navView      = buttons.ElementAt(0).Target as MUXC.NavigationView;
                    var appViewModel = (navView.DataContext as ApplicationViewModel);
                    appViewModel.Mode = ViewMode.Date;
                    var categoryName = AppResourceProvider.GetInstance().GetResourceString("DateCalculationModeText");
                    appViewModel.CategoryName = categoryName;

                    var menuItems = ((ObservableCollection <object>)navView.MenuItemsSource);
                    var flatIndex = NavCategory.GetFlatIndex(ViewMode.Date);
                    navView.SelectedItem = menuItems[flatIndex];
                    return;
                }

                if (s_ignoreNextEscape.TryGetValue(viewId, out var currentIgnoreNextEscape))
                {
                    if (currentIgnoreNextEscape && key == Windows.System.VirtualKey.Escape)
                    {
                        if (s_keepIgnoringEscape.TryGetValue(viewId, out var currentKeepIgnoringEscape))
                        {
                            if (!currentKeepIgnoringEscape)
                            {
                                HonorEscape();
                            }
                            return;
                        }
                    }
                }

                if (s_fHonorShortcuts.TryGetValue(viewId, out var currentHonorShortcuts))
                {
                    if (currentHonorShortcuts)
                    {
                        var myVirtualKey = key;
                        var lookupMap    = GetCurrentKeyDictionary(isControlKeyPressed, isShiftKeyPressed, isAltKeyPressed);
                        if (lookupMap == null)
                        {
                            return;
                        }

                        var buttons = EqualRange(lookupMap, (MyVirtualKey)myVirtualKey);
                        if (buttons.Count() <= 0)
                        {
                            return;
                        }

                        KeyboardShortcutManagerLocals.RunFirstEnabledButtonCommand(buttons);

                        // Ctrl+C and Ctrl+V shifts focus to some button because of which enter doesn't work after copy/paste. So don't shift focus if Ctrl+C or Ctrl+V
                        // is pressed. When drop down is open, pressing escape shifts focus to clear button. So dont's shift focus if drop down is open. Ctrl+Insert is
                        // equivalent to Ctrl+C and Shift+Insert is equivalent to Ctrl+V
                        //var currentIsDropDownOpen = s_IsDropDownOpen.find(viewId);
                        if (!s_IsDropDownOpen.TryGetValue(viewId, out var currentIsDropDownOpen) || !currentIsDropDownOpen)
                        {
                            // Do not Light Up Buttons when Ctrl+C, Ctrl+V, Ctrl+Insert or Shift+Insert is pressed
                            if (!(isControlKeyPressed && (key == Windows.System.VirtualKey.C || key == Windows.System.VirtualKey.V || key == Windows.System.VirtualKey.Insert))
                                & !(isShiftKeyPressed && (key == Windows.System.VirtualKey.Insert)))
                            {
                                KeyboardShortcutManagerLocals.LightUpButtons(buttons);
                            }
                        }
                    }
                }
            }