Hi
Welcome to Microsoft Q&A!
I used TextBox.KeyDown with GetKeyState(VK_CONTROL), but it did not work. but TextBox.KeyUp with GetKeyState(VK_CONTROL) worked. Why is that so?
The shortcut of the system already contains CTRL + A
, so when CTRL + A is pressed, it will be intercepted by the system.
If you want to catch CTRL + A key press, you need to override this shortcut manually via KeyboardAccelerators
<TextBox.KeyboardAccelerators>
<KeyboardAccelerator Key="A" Modifiers="Control" Invoked="OnCtrlCInvoked"/>
</TextBox.KeyboardAccelerators>
private void OnCtrlCInvoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
{
if (args.KeyboardAccelerator.Key == VirtualKey.A && args.KeyboardAccelerator.Modifiers == VirtualKeyModifiers.Control)
{
System.Diagnostics.Debug.WriteLine("Ctrl+A Pressed");
args.Handled = true;
}
}
For more details you could refer to the Doc: WinUI 3 APIs (Windows App SDK)
Thank you
Jeanine