private static bool TryGetValue( IReadOnlyDictionary <char, ConsoleInputOperation> charBindings, IReadOnlyDictionary <ConsoleKey, ConsoleInputOperation> keyBindings, IReadOnlyDictionary <ConsoleKey, ConsoleInputOperation> shiftKeyBindings, ConsoleKey key, ConsoleModifiers modifiers, out ConsoleInputOperation op) { var shiftModifiers = modifiers & ConsoleModifiers.Shift; var charWithoutNonShiftModifiers = InputUtilities.TryGetSingleChar(key, shiftModifiers); // It's important that we try the character bindings first. if (charWithoutNonShiftModifiers.HasValue && charBindings.TryGetValue(char.ToLowerInvariant(charWithoutNonShiftModifiers.Value), out op)) { return(true); } if (modifiers.HasFlag(ConsoleModifiers.Shift) && (shiftKeyBindings != null) && shiftKeyBindings.TryGetValue(key, out op)) { return(true); } return(keyBindings.TryGetValue(key, out op)); }
public void TestThatNamedOemKeysTranslateCorrectly() { InputUtilities.TryGetSingleChar(ConsoleKey.OemComma, (ConsoleModifiers)0).Should().Be(','); InputUtilities.TryGetSingleChar(ConsoleKey.OemComma, ConsoleModifiers.Shift).Should().Be('<'); InputUtilities.TryGetSingleChar(ConsoleKey.OemMinus, (ConsoleModifiers)0).Should().Be('-'); InputUtilities.TryGetSingleChar(ConsoleKey.OemMinus, ConsoleModifiers.Shift).Should().Be('_'); InputUtilities.TryGetSingleChar(ConsoleKey.OemPeriod, (ConsoleModifiers)0).Should().Be('.'); InputUtilities.TryGetSingleChar(ConsoleKey.OemPeriod, ConsoleModifiers.Shift).Should().Be('>'); InputUtilities.TryGetSingleChar(ConsoleKey.OemPlus, (ConsoleModifiers)0).Should().Be('='); InputUtilities.TryGetSingleChar(ConsoleKey.OemPlus, ConsoleModifiers.Shift).Should().Be('+'); }
public void TestThatDigitKeysTranslateCorrectly() { InputUtilities.TryGetSingleChar(ConsoleKey.D3, (ConsoleModifiers)0).Should().Be('3'); InputUtilities.TryGetSingleChar(ConsoleKey.D0, ConsoleModifiers.Shift).Should().Be(')'); InputUtilities.TryGetSingleChar(ConsoleKey.D1, ConsoleModifiers.Shift).Should().Be('!'); InputUtilities.TryGetSingleChar(ConsoleKey.D2, ConsoleModifiers.Shift).Should().Be('@'); InputUtilities.TryGetSingleChar(ConsoleKey.D3, ConsoleModifiers.Shift).Should().Be('#'); InputUtilities.TryGetSingleChar(ConsoleKey.D4, ConsoleModifiers.Shift).Should().Be('$'); InputUtilities.TryGetSingleChar(ConsoleKey.D5, ConsoleModifiers.Shift).Should().Be('%'); InputUtilities.TryGetSingleChar(ConsoleKey.D6, ConsoleModifiers.Shift).Should().Be('^'); InputUtilities.TryGetSingleChar(ConsoleKey.D7, ConsoleModifiers.Shift).Should().Be('&'); InputUtilities.TryGetSingleChar(ConsoleKey.D8, ConsoleModifiers.Shift).Should().Be('*'); InputUtilities.TryGetSingleChar(ConsoleKey.D9, ConsoleModifiers.Shift).Should().Be('('); }
private static KeyValuePair <ConsoleKeyInfo, ConsoleInputOperation> CreatePair( ConsoleKey key, ConsoleModifiers modifiers, ConsoleInputOperation op) { var c = InputUtilities.TryGetSingleChar(key, modifiers); var keyInfo = new ConsoleKeyInfo( c.GetValueOrDefault('\0'), key, modifiers.HasFlag(ConsoleModifiers.Shift), modifiers.HasFlag(ConsoleModifiers.Alt), modifiers.HasFlag(ConsoleModifiers.Control)); return(new KeyValuePair <ConsoleKeyInfo, ConsoleInputOperation>(keyInfo, op)); }
public void TestThatNumberedOemKeysTranslateCorrectly() { InputUtilities.TryGetSingleChar(ConsoleKey.Oem1, (ConsoleModifiers)0).Should().Be(';'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem1, ConsoleModifiers.Shift).Should().Be(':'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem2, (ConsoleModifiers)0).Should().Be('/'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem2, ConsoleModifiers.Shift).Should().Be('?'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem3, (ConsoleModifiers)0).Should().Be('`'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem3, ConsoleModifiers.Shift).Should().Be('~'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem4, (ConsoleModifiers)0).Should().Be('['); InputUtilities.TryGetSingleChar(ConsoleKey.Oem4, ConsoleModifiers.Shift).Should().Be('{'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem5, (ConsoleModifiers)0).Should().Be('\\'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem5, ConsoleModifiers.Shift).Should().Be('|'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem6, (ConsoleModifiers)0).Should().Be(']'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem6, ConsoleModifiers.Shift).Should().Be('}'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem7, (ConsoleModifiers)0).Should().Be('\''); InputUtilities.TryGetSingleChar(ConsoleKey.Oem7, ConsoleModifiers.Shift).Should().Be('\"'); }
public void TestThatWhitespaceKeysTranslateCorrectly() { InputUtilities.TryGetSingleChar(ConsoleKey.Spacebar, (ConsoleModifiers)0).Should().Be(' '); InputUtilities.TryGetSingleChar(ConsoleKey.Tab, (ConsoleModifiers)0).Should().Be('\t'); }
public void TestThatAlphaKeysTranslateCorrectly() { InputUtilities.TryGetSingleChar(ConsoleKey.E, (ConsoleModifiers)0).Should().Be('e'); InputUtilities.TryGetSingleChar(ConsoleKey.E, ConsoleModifiers.Shift).Should().Be('E'); InputUtilities.TryGetSingleChar(ConsoleKey.E, ConsoleModifiers.Control).Should().Be('\x05'); }
public static ConsoleKeyInfo ShiftInfo(this ConsoleKey key) { var c = InputUtilities.TryGetSingleChar(key, ConsoleModifiers.Shift); return(new ConsoleKeyInfo(c.GetValueOrDefault(), key, true, false, false)); }