locked
Mouse Back/Forward Buttons in XAML app

    Question

  • There are some old threads on this topic but none have the actual resolution (other than "this is fixed in RP"). When I click the "Back" or "Forward" buttons on my Microsoft mouse, PointerReleased is fired. How can I determine which mouse button triggered the event? In Desktop programs the Back/Forward mouse buttons trigger the WM_APPCOMMAND message with APPCOMMAND_BROWSER_FORWARD and APPCOMMAND_BROWSER_BACKWARD.

    Metro IE handles these mouse buttons as expected, so there must be a way to determine that the buttons were pressed.

    Also, my program is a SwapChainBackgroundPanel app, if that makes a difference.

    Thanks


    • Edited by henador Monday, August 20, 2012 2:46 PM
    Monday, August 20, 2012 2:35 PM

Answers

  • These map to the PointerPointProperty.IsXButton1Pressed/IsXButton2Pressed properties, which you can get from PointerEventArgs either at a control level or globally for the whole app (via Window::Current->CoreWindow):

    // handle only for a specific control, in which case you should probably also capture input to the element
    void MyPage::MyPanel_PointerPressed(Object^ sender, PointerRoutedEventArgs^ e)
    {
        bool backPressed = e->GetCurrentPoint(MyPanel)->Properties->IsXButton1Pressed;
        bool forwardPressed = e->GetCurrentPoint(MyPanel)->Properties->IsXButton2Pressed;
    }
    
    // OR, handle globally at CoreWindow level
    void MyPage::CoreWindow_PointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
    {
        bool backPressed = args->CurrentPoint->Properties->IsXButton1Pressed;
        bool forwardPressed = args->CurrentPoint->Properties->IsXButton2Pressed;
    }

    However I believe these give the current live state of the buttons, and so would always be false by the time you get PointerReleased.  You'd have to check the state in the corresponding PointerDown.

    • Marked as answer by henador Monday, August 20, 2012 6:36 PM
    Monday, August 20, 2012 4:47 PM