public void Handle(KeyRoutedEventArgs args) { var ctrlDown = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down); var altDown = Window.Current.CoreWindow.GetKeyState(VirtualKey.Menu).HasFlag(CoreVirtualKeyStates.Down); var shiftDown = Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down); foreach (var keyboardCommand in Commands) { if (keyboardCommand.Hit(ctrlDown, altDown, shiftDown, args.Key)) { if (keyboardCommand.ShouldExecute(_lastCommand)) { keyboardCommand.Execute(args); } args.Handled = true; _lastCommand = keyboardCommand; } } if (!args.Handled) { _lastCommand = null; } }
public CommandHandlerResult Handle(KeyRoutedEventArgs args) { var ctrlDown = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down); var altDown = Window.Current.CoreWindow.GetKeyState(VirtualKey.Menu).HasFlag(CoreVirtualKeyStates.Down); var shiftDown = Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down); var shouldHandle = false; var shouldSwallow = false; foreach (var command in Commands) { if (command.Hit(ctrlDown, altDown, shiftDown, args.Key)) { if (command.ShouldExecute(_lastCommand)) { command.Execute(args); } if (command.ShouldSwallowAfterExecution()) { shouldSwallow = true; } if (command.ShouldHandleAfterExecution()) { shouldHandle = true; } _lastCommand = command; break; } } if (!shouldHandle) { _lastCommand = null; } return(new CommandHandlerResult(shouldHandle, shouldSwallow)); }
public bool ShouldExecute(IKeyboardCommand <T> lastCommand) { DateTime now = DateTime.UtcNow; if (lastCommand == this && now - _lastHitTimestamp < ConsecutiveHitsInterval) { _hits++; } else { _hits = 1; } _lastHitTimestamp = now; if (_hits >= _requiredHits) { _hits = 0; return(true); } return(false); }