Page-global keyboard events in Windows Store Apps

后端 未结 2 471
無奈伤痛
無奈伤痛 2020-12-30 03:19

I\'m working on a game, a Windows Store App based on WPF and written in C#. When the player presses the Esc key, I want to pause the game and show a menu (Continue, Quit etc

2条回答
  •  盖世英雄少女心
    2020-12-30 04:16

    Try using CoreWindow.KeyDown. Assign the handler in your page and I believe it should intercept all keydown events.

    public MyPage()
    {
        CoreWindow.GetForCurrentThread().KeyDown += MyPage_KeyDown;
    }
    
    void MyPage_KeyDown(CoreWindow sender, KeyEventArgs args)
    {
        Debug.WriteLine(args.VirtualKey.ToString());
    }
    

提交回复
热议问题