Skip to content

Commit 3930998

Browse files
committed
Update BaseLayoutPage.cs
1 parent 9d2ffd3 commit 3930998

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/Files.App/Views/Layouts/BaseLayoutPage.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Files.App.Helpers.ContextFlyouts;
77
using Files.App.UserControls.Menus;
88
using Files.App.ViewModels.Layouts;
9-
using Microsoft.UI.Input;
109
using Microsoft.UI.Xaml;
1110
using Microsoft.UI.Xaml.Controls;
1211
using Microsoft.UI.Xaml.Controls.Primitives;
@@ -16,6 +15,7 @@
1615
using System.IO;
1716
using System.Runtime.CompilerServices;
1817
using System.Runtime.InteropServices.ComTypes;
18+
using System.Text;
1919
using Vanara.Extensions;
2020
using Vanara.PInvoke;
2121
using Windows.ApplicationModel.DataTransfer;
@@ -24,7 +24,7 @@
2424
using Windows.Foundation.Collections;
2525
using Windows.Storage;
2626
using Windows.System;
27-
using Windows.UI.Core;
27+
using Windows.Win32;
2828
using static Files.App.Helpers.PathNormalization;
2929
using DispatcherQueueTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer;
3030
using SortDirection = Files.App.Data.Enums.SortDirection;
@@ -1009,18 +1009,21 @@ protected virtual void Page_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
10091009
var pressedKey = e.Key;
10101010
var currentFilter = shellPage.ShellViewModel.FilesAndFoldersFilter ?? string.Empty;
10111011
var isFilterModeOn = FoldersSettingsService.KeyboardTypingBehavior == KeyboardTypingBehavior.FilterItems;
1012-
var isShiftPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift)
1013-
.HasFlag(CoreVirtualKeyStates.Down);
1012+
var buffer = new StringBuilder(4);
1013+
var state = new byte[256];
1014+
char? typedCharacter = null;
10141015

1015-
// Get typed character
1016-
var typedCharacter = pressedKey switch
1016+
if (PInvoke.GetKeyboardState(state))
10171017
{
1018-
>= VirtualKey.A and <= VirtualKey.Z => (char)('A' + (pressedKey - VirtualKey.A)),
1019-
>= VirtualKey.Number0 and <= VirtualKey.Number9 => (char)('0' + (pressedKey - VirtualKey.Number0)),
1020-
_ when (int)pressedKey == (int)Keys.OemMinus => isShiftPressed ? '_' : '-',
1021-
_ when (int)pressedKey == (int)Keys.OemPeriod => '.',
1022-
_ => (char?)null
1023-
};
1018+
var virtualKey = (uint)pressedKey;
1019+
var scanCode = PInvoke.MapVirtualKey(virtualKey, 0);
1020+
var keyboardLayout = PInvoke.GetKeyboardLayout(0);
1021+
1022+
if (Win32PInvoke.ToUnicodeEx(virtualKey, scanCode, state, buffer, buffer.Capacity, 0, keyboardLayout) > 0)
1023+
{
1024+
typedCharacter = buffer[^1];
1025+
}
1026+
}
10241027

10251028
// Handle valid character input
10261029
if (typedCharacter.HasValue && !Path.GetInvalidFileNameChars().Contains(char.ToLowerInvariant(typedCharacter.Value)))
@@ -1043,10 +1046,6 @@ _ when (int)pressedKey == (int)Keys.OemPeriod => '.',
10431046
{
10441047
switch (pressedKey)
10451048
{
1046-
case VirtualKey.Space:
1047-
shellPage.ShellViewModel.FilesAndFoldersFilter += " ";
1048-
break;
1049-
10501049
case VirtualKey.Back when currentFilter.Length > 1:
10511050
shellPage.ShellViewModel.FilesAndFoldersFilter = currentFilter[..^1];
10521051
break;

0 commit comments

Comments
 (0)