66using Files . App . Helpers . ContextFlyouts ;
77using Files . App . UserControls . Menus ;
88using Files . App . ViewModels . Layouts ;
9- using Microsoft . UI . Input ;
109using Microsoft . UI . Xaml ;
1110using Microsoft . UI . Xaml . Controls ;
1211using Microsoft . UI . Xaml . Controls . Primitives ;
1615using System . IO ;
1716using System . Runtime . CompilerServices ;
1817using System . Runtime . InteropServices . ComTypes ;
18+ using System . Text ;
1919using Vanara . Extensions ;
2020using Vanara . PInvoke ;
2121using Windows . ApplicationModel . DataTransfer ;
2424using Windows . Foundation . Collections ;
2525using Windows . Storage ;
2626using Windows . System ;
27- using Windows . UI . Core ;
27+ using Windows . Win32 ;
2828using static Files . App . Helpers . PathNormalization ;
2929using DispatcherQueueTimer = Microsoft . UI . Dispatching . DispatcherQueueTimer ;
3030using 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