Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to always listen keyboard in a uwp app with multiple frame?

I did an UWP app in xaml/c# with multiple frame, I want a page in a frame always listen the keyboard inputs but I don't know how to do, can somebody help me ?

I tried KeyDown event in the page in the frame but when I m not focus on this frame the keyboard input listener don't work ...

I want listen *, +, -, 1, 2, 3 ... keys

like image 524
sami54 Avatar asked Jan 24 '26 05:01

sami54


1 Answers

You can attach to this event:

Windows.UI.Xaml.Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated

e.g.,

Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated +=
    (window, e) =>
    {
        switch (e.VirtualKey)
        {
            case VirtualKey.Number1:
                // ...
                break;
            case VirtualKey.Number2:
                // ...
                break;
            // ...
        }
    };
like image 105
Petter Hesselberg Avatar answered Jan 26 '26 19:01

Petter Hesselberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!