Handling VirtualKey in Windows 8 Store Apps with C#

后端 未结 2 1774
北恋
北恋 2021-01-18 10:24

I\'m aware of how to handle key events, i.e.

private void Page_KeyUp(object sender, KeyRoutedEventArgs e)
{
  switch (e.Key)
  {
    case Windows.System.Virt         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-18 11:12

    Got an answer elsewhere. For those that are interested...

    public Foo()
    {
        this.InitializeComponent();
        Window.Current.CoreWindow.CharacterReceived += KeyPress;
    }
    
    void KeyPress(CoreWindow sender, CharacterReceivedEventArgs args)
    {
        args.Handled = true;
        Debug.WriteLine("KeyPress " + Convert.ToChar(args.KeyCode));
        return;
    }
    

    Even better, move the Window.Current.CoreWindow.CharacterReceived += KeyPress; into a GotFocus event handler, and add Window.Current.CoreWindow.CharacterReceived -= KeyPress; into a LostFocus event handler.

提交回复
热议问题