sami54
sami54

Reputation: 143

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

Upvotes: 3

Views: 1748

Answers (1)

Petter Hesselberg
Petter Hesselberg

Reputation: 5498

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;
            // ...
        }
    };

Upvotes: 5

Related Questions