2020-03-27 08:38:58 -07:00
# include "pch.h"
# include "SingleKeyRemapControl.h"
2020-04-20 21:01:21 -07:00
# include "keyboardmanager/common/Helpers.h"
2020-07-13 11:49:09 -07:00
# include "keyboardmanager/common/KeyboardManagerConstants.h"
# include "keyboardmanager/common/KeyboardManagerState.h"
2020-07-23 16:43:49 -07:00
# include "ShortcutControl.h"
2020-08-17 13:46:50 -07:00
# include "common/common.h"
2020-08-24 15:10:50 -07:00
# include "keyboardmanager/dll/Generated Files/resource.h"
2020-08-17 13:46:50 -07:00
extern " C " IMAGE_DOS_HEADER __ImageBase ;
2020-03-27 08:38:58 -07:00
//Both static members are initialized to null
HWND SingleKeyRemapControl : : EditKeyboardWindowHandle = nullptr ;
KeyboardManagerState * SingleKeyRemapControl : : keyboardManagerState = nullptr ;
2020-04-09 09:20:19 -07:00
// Initialized as new vector
2020-08-13 16:32:15 -07:00
RemapBuffer SingleKeyRemapControl : : singleKeyRemapBuffer ;
2020-03-27 08:38:58 -07:00
2020-07-23 16:43:49 -07:00
SingleKeyRemapControl : : SingleKeyRemapControl ( Grid table , const int colIndex )
2020-07-13 11:49:09 -07:00
{
typeKey = Button ( ) ;
typeKey . as < Button > ( ) . Width ( KeyboardManagerConstants : : RemapTableDropDownWidth ) ;
2020-08-17 13:46:50 -07:00
typeKey . as < Button > ( ) . Content ( winrt : : box_value ( GET_RESOURCE_STRING ( IDS_TYPE_BUTTON ) ) ) ;
2020-07-13 11:49:09 -07:00
singleKeyRemapControlLayout = StackPanel ( ) ;
singleKeyRemapControlLayout . as < StackPanel > ( ) . Margin ( { 0 , 0 , 0 , 10 } ) ;
singleKeyRemapControlLayout . as < StackPanel > ( ) . Spacing ( 10 ) ;
singleKeyRemapControlLayout . as < StackPanel > ( ) . Children ( ) . Append ( typeKey . as < Button > ( ) ) ;
2020-07-23 16:43:49 -07:00
// Key column
if ( colIndex = = 0 )
{
keyDropDownControlObjects . push_back ( std : : move ( std : : unique_ptr < KeyDropDownControl > ( new KeyDropDownControl ( false ) ) ) ) ;
singleKeyRemapControlLayout . as < StackPanel > ( ) . Children ( ) . Append ( keyDropDownControlObjects [ 0 ] - > GetComboBox ( ) ) ;
// Set selection handler for the drop down
keyDropDownControlObjects [ 0 ] - > SetSelectionHandler ( table , singleKeyRemapControlLayout . as < StackPanel > ( ) , colIndex , singleKeyRemapBuffer ) ;
}
// Hybrid column
else
{
hybridDropDownStackPanel = StackPanel ( ) ;
hybridDropDownStackPanel . as < StackPanel > ( ) . Spacing ( KeyboardManagerConstants : : ShortcutTableDropDownSpacing ) ;
hybridDropDownStackPanel . as < StackPanel > ( ) . Orientation ( Windows : : UI : : Xaml : : Controls : : Orientation : : Horizontal ) ;
KeyDropDownControl : : AddDropDown ( table , singleKeyRemapControlLayout . as < StackPanel > ( ) , hybridDropDownStackPanel . as < StackPanel > ( ) , colIndex , singleKeyRemapBuffer , keyDropDownControlObjects , nullptr , true , true ) ;
singleKeyRemapControlLayout . as < StackPanel > ( ) . Children ( ) . Append ( hybridDropDownStackPanel . as < StackPanel > ( ) ) ;
}
StackPanel controlStackPanel = singleKeyRemapControlLayout . as < StackPanel > ( ) ;
typeKey . as < Button > ( ) . Click ( [ & , table , colIndex , controlStackPanel ] ( winrt : : Windows : : Foundation : : IInspectable const & sender , RoutedEventArgs const & ) {
// Using the XamlRoot of the typeKey to get the root of the XAML host
if ( colIndex = = 0 )
{
keyboardManagerState - > SetUIState ( KeyboardManagerUIState : : DetectSingleKeyRemapWindowActivated , EditKeyboardWindowHandle ) ;
createDetectKeyWindow ( sender , sender . as < Button > ( ) . XamlRoot ( ) , * keyboardManagerState ) ;
}
else
{
keyboardManagerState - > SetUIState ( KeyboardManagerUIState : : DetectShortcutWindowInEditKeyboardWindowActivated , EditKeyboardWindowHandle ) ;
ShortcutControl : : createDetectShortcutWindow ( sender , sender . as < Button > ( ) . XamlRoot ( ) , * keyboardManagerState , colIndex , table , keyDropDownControlObjects , controlStackPanel , nullptr , true , true , EditKeyboardWindowHandle , singleKeyRemapBuffer ) ;
}
} ) ;
2020-07-13 11:49:09 -07:00
singleKeyRemapControlLayout . as < StackPanel > ( ) . UpdateLayout ( ) ;
}
2020-03-27 08:38:58 -07:00
// Function to add a new row to the remap keys table. If the originalKey and newKey args are provided, then the displayed remap keys are set to those values.
2020-07-23 16:43:49 -07:00
void SingleKeyRemapControl : : AddNewControlKeyRemapRow ( Grid & parent , std : : vector < std : : vector < std : : unique_ptr < SingleKeyRemapControl > > > & keyboardRemapControlObjects , const DWORD originalKey , const std : : variant < DWORD , Shortcut > newKey )
2020-03-27 08:38:58 -07:00
{
2020-04-18 16:12:26 -07:00
// Create new SingleKeyRemapControl objects dynamically so that we does not get destructed
std : : vector < std : : unique_ptr < SingleKeyRemapControl > > newrow ;
2020-05-11 10:10:36 -07:00
newrow . push_back ( std : : move ( std : : unique_ptr < SingleKeyRemapControl > ( new SingleKeyRemapControl ( parent , 0 ) ) ) ) ;
newrow . push_back ( std : : move ( std : : unique_ptr < SingleKeyRemapControl > ( new SingleKeyRemapControl ( parent , 1 ) ) ) ) ;
2020-04-18 16:12:26 -07:00
keyboardRemapControlObjects . push_back ( std : : move ( newrow ) ) ;
2020-04-23 09:14:16 -07:00
// Add to grid
parent . RowDefinitions ( ) . Append ( RowDefinition ( ) ) ;
2020-05-08 17:34:24 -07:00
parent . SetColumn ( keyboardRemapControlObjects [ keyboardRemapControlObjects . size ( ) - 1 ] [ 0 ] - > getSingleKeyRemapControl ( ) , KeyboardManagerConstants : : RemapTableOriginalColIndex ) ;
2020-04-23 09:14:16 -07:00
parent . SetRow ( keyboardRemapControlObjects [ keyboardRemapControlObjects . size ( ) - 1 ] [ 0 ] - > getSingleKeyRemapControl ( ) , parent . RowDefinitions ( ) . Size ( ) - 1 ) ;
2020-05-08 17:34:24 -07:00
parent . SetColumn ( keyboardRemapControlObjects [ keyboardRemapControlObjects . size ( ) - 1 ] [ 1 ] - > getSingleKeyRemapControl ( ) , KeyboardManagerConstants : : RemapTableNewColIndex ) ;
2020-04-23 09:14:16 -07:00
parent . SetRow ( keyboardRemapControlObjects [ keyboardRemapControlObjects . size ( ) - 1 ] [ 1 ] - > getSingleKeyRemapControl ( ) , parent . RowDefinitions ( ) . Size ( ) - 1 ) ;
2020-03-27 08:38:58 -07:00
// SingleKeyRemapControl for the original key.
2020-04-23 09:14:16 -07:00
parent . Children ( ) . Append ( keyboardRemapControlObjects [ keyboardRemapControlObjects . size ( ) - 1 ] [ 0 ] - > getSingleKeyRemapControl ( ) ) ;
2020-05-08 17:34:24 -07:00
// Arrow icon
FontIcon arrowIcon ;
2020-07-13 11:49:09 -07:00
arrowIcon . FontFamily ( Media : : FontFamily ( L " Segoe MDL2 Assets " ) ) ;
2020-05-08 17:34:24 -07:00
arrowIcon . Glyph ( L " \xE72A " ) ;
arrowIcon . VerticalAlignment ( VerticalAlignment : : Center ) ;
arrowIcon . HorizontalAlignment ( HorizontalAlignment : : Center ) ;
parent . SetColumn ( arrowIcon , KeyboardManagerConstants : : RemapTableArrowColIndex ) ;
parent . SetRow ( arrowIcon , parent . RowDefinitions ( ) . Size ( ) - 1 ) ;
parent . Children ( ) . Append ( arrowIcon ) ;
2020-04-18 16:12:26 -07:00
// SingleKeyRemapControl for the new remap key
2020-04-23 09:14:16 -07:00
parent . Children ( ) . Append ( keyboardRemapControlObjects [ keyboardRemapControlObjects . size ( ) - 1 ] [ 1 ] - > getSingleKeyRemapControl ( ) ) ;
2020-03-27 08:38:58 -07:00
// Set the key text if the two keys are not null (i.e. default args)
2020-07-23 16:43:49 -07:00
if ( originalKey ! = NULL & & ! ( newKey . index ( ) = = 0 & & std : : get < DWORD > ( newKey ) = = NULL ) & & ! ( newKey . index ( ) = = 1 & & ! std : : get < Shortcut > ( newKey ) . IsValidShortcut ( ) ) )
2020-03-27 08:38:58 -07:00
{
2020-08-13 16:32:15 -07:00
singleKeyRemapBuffer . push_back ( std : : make_pair < RemapBufferItem , std : : wstring > ( RemapBufferItem { originalKey , newKey } , L " " ) ) ;
2020-04-18 16:12:26 -07:00
std : : vector < DWORD > keyCodes = keyboardManagerState - > keyboardMap . GetKeyCodeList ( ) ;
2020-07-23 16:43:49 -07:00
std : : vector < DWORD > shortcutListKeyCodes = keyboardManagerState - > keyboardMap . GetKeyCodeList ( true ) ;
2020-04-18 16:12:26 -07:00
auto it = std : : find ( keyCodes . begin ( ) , keyCodes . end ( ) , originalKey ) ;
if ( it ! = keyCodes . end ( ) )
{
2020-07-23 16:43:49 -07:00
keyboardRemapControlObjects [ keyboardRemapControlObjects . size ( ) - 1 ] [ 0 ] - > keyDropDownControlObjects [ 0 ] - > SetSelectedIndex ( ( int32_t ) std : : distance ( keyCodes . begin ( ) , it ) ) ;
2020-04-18 16:12:26 -07:00
}
2020-07-23 16:43:49 -07:00
if ( newKey . index ( ) = = 0 )
{
it = std : : find ( shortcutListKeyCodes . begin ( ) , shortcutListKeyCodes . end ( ) , std : : get < DWORD > ( newKey ) ) ;
if ( it ! = shortcutListKeyCodes . end ( ) )
{
keyboardRemapControlObjects [ keyboardRemapControlObjects . size ( ) - 1 ] [ 1 ] - > keyDropDownControlObjects [ 0 ] - > SetSelectedIndex ( ( int32_t ) std : : distance ( shortcutListKeyCodes . begin ( ) , it ) ) ;
}
}
else
2020-04-18 16:12:26 -07:00
{
2020-07-23 16:43:49 -07:00
KeyDropDownControl : : AddShortcutToControl ( std : : get < Shortcut > ( newKey ) , parent , keyboardRemapControlObjects [ keyboardRemapControlObjects . size ( ) - 1 ] [ 1 ] - > hybridDropDownStackPanel . as < StackPanel > ( ) , * keyboardManagerState , 1 , keyboardRemapControlObjects [ keyboardRemapControlObjects . size ( ) - 1 ] [ 1 ] - > keyDropDownControlObjects , singleKeyRemapBuffer , keyboardRemapControlObjects [ keyboardRemapControlObjects . size ( ) - 1 ] [ 1 ] - > singleKeyRemapControlLayout . as < StackPanel > ( ) , nullptr , true , true ) ;
2020-04-18 16:12:26 -07:00
}
2020-04-09 09:20:19 -07:00
}
else
{
// Initialize both keys to NULL
2020-08-13 16:32:15 -07:00
singleKeyRemapBuffer . push_back ( std : : make_pair < RemapBufferItem , std : : wstring > ( RemapBufferItem { NULL , NULL } , L " " ) ) ;
2020-03-27 08:38:58 -07:00
}
// Delete row button
Windows : : UI : : Xaml : : Controls : : Button deleteRemapKeys ;
FontIcon deleteSymbol ;
2020-07-13 11:49:09 -07:00
deleteSymbol . FontFamily ( Media : : FontFamily ( L " Segoe MDL2 Assets " ) ) ;
2020-03-27 08:38:58 -07:00
deleteSymbol . Glyph ( L " \xE74D " ) ;
deleteRemapKeys . Content ( deleteSymbol ) ;
2020-05-06 08:34:26 -07:00
deleteRemapKeys . Background ( Media : : SolidColorBrush ( Colors : : Transparent ( ) ) ) ;
2020-05-08 17:34:24 -07:00
deleteRemapKeys . HorizontalAlignment ( HorizontalAlignment : : Center ) ;
2020-04-20 08:22:36 -07:00
deleteRemapKeys . Click ( [ & ] ( winrt : : Windows : : Foundation : : IInspectable const & sender , RoutedEventArgs const & ) {
2020-04-23 09:14:16 -07:00
Button currentButton = sender . as < Button > ( ) ;
2020-03-27 08:38:58 -07:00
uint32_t index ;
2020-04-23 09:14:16 -07:00
// Get index of delete button
UIElementCollection children = parent . Children ( ) ;
children . IndexOf ( currentButton , index ) ;
2020-05-08 17:34:24 -07:00
uint32_t lastIndexInRow = index + ( ( KeyboardManagerConstants : : RemapTableColCount - 1 ) - KeyboardManagerConstants : : RemapTableRemoveColIndex ) ;
2020-04-23 09:14:16 -07:00
// Change the row index of elements appearing after the current row, as we will delete the row definition
2020-04-26 15:09:40 -07:00
for ( uint32_t i = lastIndexInRow + 1 ; i < children . Size ( ) ; i + + )
2020-04-23 09:14:16 -07:00
{
int32_t elementRowIndex = parent . GetRow ( children . GetAt ( i ) . as < FrameworkElement > ( ) ) ;
parent . SetRow ( children . GetAt ( i ) . as < FrameworkElement > ( ) , elementRowIndex - 1 ) ;
}
2020-05-08 17:34:24 -07:00
for ( int i = 0 ; i < KeyboardManagerConstants : : RemapTableColCount ; i + + )
{
parent . Children ( ) . RemoveAt ( lastIndexInRow - i ) ;
}
2020-04-23 09:14:16 -07:00
// Calculate row index in the buffer from the grid child index (first two children are header elements and then three children in each row)
2020-05-08 17:34:24 -07:00
int bufferIndex = ( lastIndexInRow - KeyboardManagerConstants : : RemapTableHeaderCount ) / KeyboardManagerConstants : : RemapTableColCount ;
2020-04-23 09:14:16 -07:00
// Delete the row definition
parent . RowDefinitions ( ) . RemoveAt ( bufferIndex + 1 ) ;
// delete the row from the buffer.
singleKeyRemapBuffer . erase ( singleKeyRemapBuffer . begin ( ) + bufferIndex ) ;
2020-04-18 16:12:26 -07:00
// delete the SingleKeyRemapControl objects so that they get destructed
2020-04-23 09:14:16 -07:00
keyboardRemapControlObjects . erase ( keyboardRemapControlObjects . begin ( ) + bufferIndex ) ;
2020-03-27 08:38:58 -07:00
} ) ;
2020-05-08 17:34:24 -07:00
parent . SetColumn ( deleteRemapKeys , KeyboardManagerConstants : : RemapTableRemoveColIndex ) ;
2020-04-23 09:14:16 -07:00
parent . SetRow ( deleteRemapKeys , parent . RowDefinitions ( ) . Size ( ) - 1 ) ;
parent . Children ( ) . Append ( deleteRemapKeys ) ;
2020-04-26 15:09:40 -07:00
parent . UpdateLayout ( ) ;
2020-03-27 08:38:58 -07:00
}
// Function to return the stack panel element of the SingleKeyRemapControl. This is the externally visible UI element which can be used to add it to other layouts
StackPanel SingleKeyRemapControl : : getSingleKeyRemapControl ( )
{
2020-07-13 11:49:09 -07:00
return singleKeyRemapControlLayout . as < StackPanel > ( ) ;
2020-03-27 08:38:58 -07:00
}
// Function to create the detect remap key UI window
2020-07-23 16:43:49 -07:00
void SingleKeyRemapControl : : createDetectKeyWindow ( winrt : : Windows : : Foundation : : IInspectable const & sender , XamlRoot xamlRoot , KeyboardManagerState & keyboardManagerState )
2020-03-27 08:38:58 -07:00
{
// ContentDialog for detecting remap key. This is the parent UI element.
ContentDialog detectRemapKeyBox ;
2020-04-16 09:16:48 -07:00
2020-03-27 08:38:58 -07:00
// ContentDialog requires manually setting the XamlRoot (https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.contentdialog#contentdialog-in-appwindow-or-xaml-islands)
detectRemapKeyBox . XamlRoot ( xamlRoot ) ;
2020-08-17 13:46:50 -07:00
detectRemapKeyBox . Title ( box_value ( GET_RESOURCE_STRING ( IDS_TYPEKEY_TITLE ) ) ) ;
2020-04-16 09:16:48 -07:00
detectRemapKeyBox . IsPrimaryButtonEnabled ( false ) ;
2020-03-27 08:38:58 -07:00
detectRemapKeyBox . IsSecondaryButtonEnabled ( false ) ;
// Get the linked text block for the "Type Key" button that was clicked
2020-04-20 08:22:36 -07:00
ComboBox linkedRemapDropDown = KeyboardManagerHelper : : getSiblingElement ( sender ) . as < ComboBox > ( ) ;
2020-03-27 08:38:58 -07:00
2020-04-16 09:16:48 -07:00
auto unregisterKeys = [ & keyboardManagerState ] ( ) {
std : : thread t1 ( & KeyboardManagerState : : UnregisterKeyDelay , & keyboardManagerState , VK_ESCAPE ) ;
std : : thread t2 ( & KeyboardManagerState : : UnregisterKeyDelay , & keyboardManagerState , VK_RETURN ) ;
t1 . detach ( ) ;
t2 . detach ( ) ;
} ;
2020-05-13 10:13:44 -07:00
auto onPressEnter = [ linkedRemapDropDown ,
detectRemapKeyBox ,
& keyboardManagerState ,
unregisterKeys ] {
2020-03-27 08:38:58 -07:00
// Save the detected key in the linked text block
DWORD detectedKey = keyboardManagerState . GetDetectedSingleRemapKey ( ) ;
2020-04-09 09:20:19 -07:00
2020-03-27 08:38:58 -07:00
if ( detectedKey ! = NULL )
{
2020-04-18 16:12:26 -07:00
std : : vector < DWORD > keyCodeList = keyboardManagerState . keyboardMap . GetKeyCodeList ( ) ;
// Update the drop down list with the new language to ensure that the correct key is displayed
2020-04-20 21:01:21 -07:00
linkedRemapDropDown . ItemsSource ( KeyboardManagerHelper : : ToBoxValue ( keyboardManagerState . keyboardMap . GetKeyNameList ( ) ) ) ;
2020-04-18 16:12:26 -07:00
auto it = std : : find ( keyCodeList . begin ( ) , keyCodeList . end ( ) , detectedKey ) ;
if ( it ! = keyCodeList . end ( ) )
{
linkedRemapDropDown . SelectedIndex ( ( int32_t ) std : : distance ( keyCodeList . begin ( ) , it ) ) ;
}
2020-03-27 08:38:58 -07:00
}
2020-05-13 10:13:44 -07:00
// Hide the type key UI
detectRemapKeyBox . Hide ( ) ;
} ;
2020-03-27 08:38:58 -07:00
2020-05-13 10:13:44 -07:00
auto onReleaseEnter = [ & keyboardManagerState ,
unregisterKeys ] {
2020-03-27 08:38:58 -07:00
// Reset the keyboard manager UI state
keyboardManagerState . ResetUIState ( ) ;
2020-05-04 15:49:37 -07:00
// Revert UI state back to Edit Keyboard window
keyboardManagerState . SetUIState ( KeyboardManagerUIState : : EditKeyboardWindowActivated , EditKeyboardWindowHandle ) ;
2020-04-16 09:16:48 -07:00
unregisterKeys ( ) ;
2020-05-13 10:13:44 -07:00
} ;
auto onAccept = [ onPressEnter ,
onReleaseEnter ] {
onPressEnter ( ) ;
onReleaseEnter ( ) ;
2020-04-16 09:16:48 -07:00
} ;
TextBlock primaryButtonText ;
2020-08-17 13:46:50 -07:00
primaryButtonText . Text ( GET_RESOURCE_STRING ( IDS_OK_BUTTON ) ) ;
2020-04-16 09:16:48 -07:00
Button primaryButton ;
primaryButton . HorizontalAlignment ( HorizontalAlignment : : Stretch ) ;
primaryButton . Margin ( { 2 , 2 , 2 , 2 } ) ;
primaryButton . Content ( primaryButtonText ) ;
2020-04-20 08:22:36 -07:00
primaryButton . Click ( [ onAccept ] ( winrt : : Windows : : Foundation : : IInspectable const & sender , RoutedEventArgs const & ) {
2020-04-16 09:16:48 -07:00
onAccept ( ) ;
2020-03-27 08:38:58 -07:00
} ) ;
2020-04-16 09:16:48 -07:00
keyboardManagerState . RegisterKeyDelay (
VK_RETURN ,
std : : bind ( & KeyboardManagerState : : SelectDetectedRemapKey , & keyboardManagerState , std : : placeholders : : _1 ) ,
2020-05-13 10:13:44 -07:00
[ primaryButton , onPressEnter , detectRemapKeyBox ] ( DWORD ) {
2020-04-16 09:16:48 -07:00
detectRemapKeyBox . Dispatcher ( ) . RunAsync (
Windows : : UI : : Core : : CoreDispatcherPriority : : Normal ,
2020-05-13 10:13:44 -07:00
[ primaryButton , onPressEnter ] {
2020-04-21 13:42:06 -07:00
// Use the base medium low brush to be consistent with the theme
primaryButton . Background ( Windows : : UI : : Xaml : : Application : : Current ( ) . Resources ( ) . Lookup ( box_value ( L " SystemControlBackgroundBaseMediumLowBrush " ) ) . as < Windows : : UI : : Xaml : : Media : : SolidColorBrush > ( ) ) ;
2020-05-13 10:13:44 -07:00
onPressEnter ( ) ;
2020-04-16 09:16:48 -07:00
} ) ;
} ,
2020-05-13 10:13:44 -07:00
[ onReleaseEnter ] ( DWORD ) {
onReleaseEnter ( ) ;
2020-04-16 09:16:48 -07:00
} ) ;
TextBlock cancelButtonText ;
2020-08-17 13:46:50 -07:00
cancelButtonText . Text ( GET_RESOURCE_STRING ( IDS_CANCEL_BUTTON ) ) ;
2020-04-16 09:16:48 -07:00
Button cancelButton ;
cancelButton . HorizontalAlignment ( HorizontalAlignment : : Stretch ) ;
cancelButton . Margin ( { 2 , 2 , 2 , 2 } ) ;
cancelButton . Content ( cancelButtonText ) ;
2020-03-27 08:38:58 -07:00
// Cancel button
2020-04-20 08:22:36 -07:00
cancelButton . Click ( [ detectRemapKeyBox , unregisterKeys , & keyboardManagerState ] ( winrt : : Windows : : Foundation : : IInspectable const & sender , RoutedEventArgs const & ) {
2020-03-27 08:38:58 -07:00
// Reset the keyboard manager UI state
keyboardManagerState . ResetUIState ( ) ;
2020-05-04 15:49:37 -07:00
// Revert UI state back to Edit Keyboard window
keyboardManagerState . SetUIState ( KeyboardManagerUIState : : EditKeyboardWindowActivated , EditKeyboardWindowHandle ) ;
2020-04-16 09:16:48 -07:00
unregisterKeys ( ) ;
detectRemapKeyBox . Hide ( ) ;
2020-03-27 08:38:58 -07:00
} ) ;
2020-04-16 09:16:48 -07:00
keyboardManagerState . RegisterKeyDelay (
VK_ESCAPE ,
std : : bind ( & KeyboardManagerState : : SelectDetectedRemapKey , & keyboardManagerState , std : : placeholders : : _1 ) ,
[ & keyboardManagerState , detectRemapKeyBox , unregisterKeys ] ( DWORD ) {
detectRemapKeyBox . Dispatcher ( ) . RunAsync (
Windows : : UI : : Core : : CoreDispatcherPriority : : Normal ,
[ detectRemapKeyBox ] {
detectRemapKeyBox . Hide ( ) ;
} ) ;
keyboardManagerState . ResetUIState ( ) ;
2020-05-04 15:49:37 -07:00
// Revert UI state back to Edit Keyboard window
keyboardManagerState . SetUIState ( KeyboardManagerUIState : : EditKeyboardWindowActivated , EditKeyboardWindowHandle ) ;
2020-04-16 09:16:48 -07:00
unregisterKeys ( ) ;
} ,
nullptr ) ;
2020-03-27 08:38:58 -07:00
// StackPanel parent for the displayed text in the dialog
Windows : : UI : : Xaml : : Controls : : StackPanel stackPanel ;
2020-04-08 14:31:31 -07:00
detectRemapKeyBox . Content ( stackPanel ) ;
2020-03-27 08:38:58 -07:00
// Header textblock
TextBlock text ;
2020-08-17 13:46:50 -07:00
text . Text ( GET_RESOURCE_STRING ( IDS_TYPEKEY_HEADER ) ) ;
2020-03-27 08:38:58 -07:00
text . Margin ( { 0 , 0 , 0 , 10 } ) ;
stackPanel . Children ( ) . Append ( text ) ;
2020-04-08 14:31:31 -07:00
// Target StackPanel to place the selected key
Windows : : UI : : Xaml : : Controls : : StackPanel keyStackPanel ;
keyStackPanel . Orientation ( Orientation : : Horizontal ) ;
2020-04-16 09:16:48 -07:00
stackPanel . Children ( ) . Append ( keyStackPanel ) ;
TextBlock holdEscInfo ;
2020-08-17 13:46:50 -07:00
holdEscInfo . Text ( GET_RESOURCE_STRING ( IDS_TYPE_HOLDESC ) ) ;
2020-04-16 09:16:48 -07:00
holdEscInfo . FontSize ( 12 ) ;
holdEscInfo . Margin ( { 0 , 20 , 0 , 0 } ) ;
stackPanel . Children ( ) . Append ( holdEscInfo ) ;
TextBlock holdEnterInfo ;
2020-08-17 13:46:50 -07:00
holdEnterInfo . Text ( GET_RESOURCE_STRING ( IDS_TYPE_HOLDENTER ) ) ;
2020-04-16 09:16:48 -07:00
holdEnterInfo . FontSize ( 12 ) ;
holdEnterInfo . Margin ( { 0 , 0 , 0 , 0 } ) ;
stackPanel . Children ( ) . Append ( holdEnterInfo ) ;
ColumnDefinition primaryButtonColumn ;
ColumnDefinition cancelButtonColumn ;
Grid buttonPanel ;
buttonPanel . Margin ( { 0 , 20 , 0 , 0 } ) ;
buttonPanel . HorizontalAlignment ( HorizontalAlignment : : Stretch ) ;
buttonPanel . ColumnDefinitions ( ) . Append ( primaryButtonColumn ) ;
buttonPanel . ColumnDefinitions ( ) . Append ( cancelButtonColumn ) ;
buttonPanel . SetColumn ( primaryButton , 0 ) ;
buttonPanel . SetColumn ( cancelButton , 1 ) ;
buttonPanel . Children ( ) . Append ( primaryButton ) ;
buttonPanel . Children ( ) . Append ( cancelButton ) ;
stackPanel . Children ( ) . Append ( buttonPanel ) ;
2020-03-27 08:38:58 -07:00
stackPanel . UpdateLayout ( ) ;
// Configure the keyboardManagerState to store the UI information.
2020-04-08 14:31:31 -07:00
keyboardManagerState . ConfigureDetectSingleKeyRemapUI ( keyStackPanel ) ;
2020-03-27 08:38:58 -07:00
// Show the dialog
detectRemapKeyBox . ShowAsync ( ) ;
}