locked
Unexpected behavior in Windows.Core.UI.CorePhysicalKeyStatus.IsMenuKeyDown RRS feed

  • Question

  • Forum,

    I have uncovered something peculiar while trying to implement accelerator keys in my WinRT app.  I was originally handling key down and key up for the Alt (a.k.a Menu) key, but I found that if you Alt+Tab to a different app, the app doesn't receive a key up from the Akt key.  To fix this, I decided I might try to handle something from the KeyDown event args: Windows.Core.UI.CorePhysicalKeyStatus.IsMenuKeyDown.  However, I think it might be broken, cause I get something bizzare when I try to handle the KeyDown event of a page:

    private void pageRoot_KeyDown(object sender, KeyRoutedEventArgs e) { if (e.Key == Windows.System.VirtualKey.Menu) { if (!e.KeyStatus.IsMenuKeyDown) { throw new Exception("IsMenuKeyDown not working"); } } }

    When I press the "Alt" key with the page focused, I get the exception indicated above. Is it expected that IsMenuKeyDown would be false when the Menu key is pressed, or is there something wrong here?
    Monday, August 6, 2012 5:44 PM

Answers

  • I got your project, and can reproduce the problem on RTM bits.  I'm going to file a bug on this.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, August 14, 2012 1:57 PM
    Moderator

All replies

  • It sounds like you're going through this sequence of events:

    1) You are in App1
    2) You press the Alt key, thus receiving the KeyDown event
    3) You press the Tab key, which transfers control to the system to switch between open apps
    4) You focus on another Modern app (App2), and let go
    5) App2 now gets focus, but does not receive the KeyUp event because it wasn't the focused app during the time of the key up

    Is this about right?  That sounds like it's by-design.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, August 7, 2012 2:52 PM
    Moderator
  • The issue isn't the fact that the first app isn't receiving key up; that much I get.  What I don't userstand is how Windows.Core.UI.CorePhysicalKeyStatus.IsMenuKeyDown is false even when I press the Alt key.
    Tuesday, August 7, 2012 4:33 PM
  • Are you saying that it shows as false in App2, inside the pageRoot_KeyDown method?  My question is, how does that event get called if you switched to it using alt+tab?


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, August 7, 2012 4:36 PM
    Moderator
  • Let's set aside the Alt+Tab situation for a moment.  In the KeyDown handler above, when you pess Alt--for any reason--, Windows.Core.UI.CorePhysicalKeyStatus.IsMenuKeyDown is false.  This occurs even though KeyRoutedEventArgs.Key == Windows.System.VirtualKey.Menu.  So the event argument says that the Alt key is down, but the property in CorePhysicalKeyStatus says that it is not down. 
    Tuesday, August 7, 2012 5:39 PM
  • Which event are you listening to on the pageRoot_KeyDown method?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, August 10, 2012 5:02 PM
    Moderator
  • Windows.UI.Xaml.Controls.Page.KeyDown
    Friday, August 10, 2012 5:36 PM
  • I'm having a terrible time trying to reproduce this. I'm trying to figure out how to get the page to respond to a keydown event - I know that the page needs to have focus, but I can't seem to give it to the page.  What are you doing in this case?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, August 13, 2012 7:51 PM
    Moderator
  • If you stick a button on the page, that should do it.  Alternatively, I can send you or put a project somewhere that will reproduce the issue.

    Monday, August 13, 2012 8:15 PM
  • Yes, send me your project: MSMALL at Microsoft


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, August 13, 2012 9:04 PM
    Moderator
  • I got your project, and can reproduce the problem on RTM bits.  I'm going to file a bug on this.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, August 14, 2012 1:57 PM
    Moderator
  • Is there a way I can check bug-report status to determine if this has been fixed? I'm still seeing the incorrect behavior on Windows 8.1 Update 1 and I'd like to know if this bug is still active or if my test code is wrong. Thank you.
    Friday, May 2, 2014 2:16 AM
  • This was not fixed. Here's a workaround:

    private void pageRoot_KeyDown(object sender, KeyRoutedEventArgs e) 
    { 
    if (e.Key == Windows.System.VirtualKey.Menu) 
    { 
    var state = Window.Current.CoreWindow.GetKeyState(Windows.System.VirtualKey.Menu); 
    if (!state.HasFlag(Windows.UI.Core.CoreVirtualKeyStates.Down)) 
    throw new Exception("asdf!"); 
    } 
    }
    


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Proposed as answer by MarkT Friday, May 2, 2014 6:44 PM
    Friday, May 2, 2014 6:38 PM
    Moderator
  • Thanks for the verification, Matt!
    Friday, May 2, 2014 6:45 PM