mirror of
https://github.com/microsoft/terminal.git
synced 2025-12-13 21:42:26 -06:00
Make KeyEvent char data a little less confusing (#14747)
When working on #14745 I found `KeyEvent`s a little hard to read in the debugger. I noticed that this is because of sign extension when converting `char`s to `wchar_t`s in `KeyEvent::SetCharData`.
This commit is contained in:
parent
282c583731
commit
ddc349be81
@ -194,7 +194,7 @@ _Ret_range_(0, cbAnsi)
|
|||||||
|
|
||||||
memcpy(TmpUni, pwchUnicode, cchUnicode * sizeof(WCHAR));
|
memcpy(TmpUni, pwchUnicode, cchUnicode * sizeof(WCHAR));
|
||||||
|
|
||||||
BYTE AsciiDbcs[2];
|
CHAR AsciiDbcs[2];
|
||||||
AsciiDbcs[1] = 0;
|
AsciiDbcs[1] = 0;
|
||||||
|
|
||||||
ULONG i, j;
|
ULONG i, j;
|
||||||
|
|||||||
@ -209,7 +209,7 @@ void HandleKeyEvent(const HWND hWnd,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
keyEvent.SetCharData(0);
|
keyEvent.SetCharData(L'\0');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -220,7 +220,7 @@ void HandleKeyEvent(const HWND hWnd,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
keyEvent.SetActiveModifierKeys(ControlKeyState);
|
keyEvent.SetActiveModifierKeys(ControlKeyState);
|
||||||
keyEvent.SetCharData(0);
|
keyEvent.SetCharData(L'\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
const INPUT_KEY_INFO inputKeyInfo(VirtualKeyCode, ControlKeyState);
|
const INPUT_KEY_INFO inputKeyInfo(VirtualKeyCode, ControlKeyState);
|
||||||
|
|||||||
@ -44,6 +44,14 @@ void KeyEvent::SetVirtualScanCode(const WORD virtualScanCode) noexcept
|
|||||||
_virtualScanCode = virtualScanCode;
|
_virtualScanCode = virtualScanCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KeyEvent::SetCharData(const char character) noexcept
|
||||||
|
{
|
||||||
|
// With MSVC char is signed by default and the conversion to wchar_t (unsigned) would turn negative
|
||||||
|
// chars into very large wchar_t values. While this doesn't pose a problem per se (even with such sign
|
||||||
|
// extension, the lower 8 bit stay the same), it makes debugging and reading key events more difficult.
|
||||||
|
_charData = til::as_unsigned(character);
|
||||||
|
}
|
||||||
|
|
||||||
void KeyEvent::SetCharData(const wchar_t character) noexcept
|
void KeyEvent::SetCharData(const wchar_t character) noexcept
|
||||||
{
|
{
|
||||||
_charData = character;
|
_charData = character;
|
||||||
|
|||||||
@ -290,6 +290,7 @@ public:
|
|||||||
void SetRepeatCount(const WORD repeatCount) noexcept;
|
void SetRepeatCount(const WORD repeatCount) noexcept;
|
||||||
void SetVirtualKeyCode(const WORD virtualKeyCode) noexcept;
|
void SetVirtualKeyCode(const WORD virtualKeyCode) noexcept;
|
||||||
void SetVirtualScanCode(const WORD virtualScanCode) noexcept;
|
void SetVirtualScanCode(const WORD virtualScanCode) noexcept;
|
||||||
|
void SetCharData(const char character) noexcept;
|
||||||
void SetCharData(const wchar_t character) noexcept;
|
void SetCharData(const wchar_t character) noexcept;
|
||||||
|
|
||||||
void SetActiveModifierKeys(const DWORD activeModifierKeys) noexcept;
|
void SetActiveModifierKeys(const DWORD activeModifierKeys) noexcept;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user