From 91ccf4e9c643917472cd55d42094c2a1c29e05ac Mon Sep 17 00:00:00 2001 From: Nikolay Nikolov Date: Sat, 12 Mar 2022 23:51:55 +0200 Subject: [PATCH] + introduced the CurrentLegacy2EnhancedKeyEventTranslationCodePage private variable in the keyboard unit. It is used for translating AsciiChar to UnicodeChar in non-enhanced (i.e. non-unicode) consoles. It can be initialized in SysInitKeyboard in non-unicode consoles, so they can return unicode characters as well. --- packages/rtl-console/src/inc/keyboard.inc | 25 +++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/rtl-console/src/inc/keyboard.inc b/packages/rtl-console/src/inc/keyboard.inc index c8b3916078..ebfc6fb979 100644 --- a/packages/rtl-console/src/inc/keyboard.inc +++ b/packages/rtl-console/src/inc/keyboard.inc @@ -13,6 +13,7 @@ var PendingKeyEvent : TKeyEvent; + CurrentLegacy2EnhancedKeyEventTranslationCodePage: TSystemCodePage; procedure PutKeyEvent(KeyEvent: TKeyEvent); begin @@ -64,6 +65,7 @@ procedure InitKeyboard; begin If Not KeyboardInitialized then begin + CurrentLegacy2EnhancedKeyEventTranslationCodePage := 437; If Assigned(CurrentKeyBoardDriver.InitDriver) Then CurrentKeyBoardDriver.InitDriver(); KeyboardInitialized:=True; @@ -224,6 +226,8 @@ function ConvertToEnhancedKeyEvent(KeyEvent: TKeyEvent): TEnhancedKeyEvent; var TranslatedKeyEvent: TKeyEvent; ShiftState: Byte; + tmpS: RawByteString; + tmpUS: UnicodeString; begin ConvertToEnhancedKeyEvent:=NilEnhancedKeyEvent; if KeyEvent=0 then @@ -264,12 +268,21 @@ begin ConvertToEnhancedKeyEvent.VirtualScanCode:=TranslatedKeyEvent and $ffff; end; { todo: set ConvertToEnhancedKeyEvent.Flags } - if (ConvertToEnhancedKeyEvent.UnicodeChar=WideChar(0)) and - (ConvertToEnhancedKeyEvent.AsciiChar>=#0) and - (ConvertToEnhancedKeyEvent.AsciiChar<=#127) then - ConvertToEnhancedKeyEvent.UnicodeChar:=WideChar(ConvertToEnhancedKeyEvent.AsciiChar); - { todo: maybe also convert extended ASCII (>=#128) codes to Unicode as well - (according to the console code page) } + if (ConvertToEnhancedKeyEvent.UnicodeChar=WideChar(0)) then + begin + if (ConvertToEnhancedKeyEvent.AsciiChar>=#0) and + (ConvertToEnhancedKeyEvent.AsciiChar<=#127) then + ConvertToEnhancedKeyEvent.UnicodeChar:=WideChar(ConvertToEnhancedKeyEvent.AsciiChar) + else + begin + SetLength(tmpS, 1); + tmpS[1]:=ConvertToEnhancedKeyEvent.AsciiChar; + System.SetCodePage(tmpS,CurrentLegacy2EnhancedKeyEventTranslationCodePage,False); + tmpUS:=tmpS; + if Length(tmpUS) = 1 then + ConvertToEnhancedKeyEvent.UnicodeChar := tmpUS[1]; + end; + end; end; function DefaultGetEnhancedKeyEvent: TEnhancedKeyEvent;