Passing window events to enclosing app

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Victory
Earned some good credits
Earned some good credits
Posts: 115
Joined: Fri Mar 19, 2010 1:20 am

Passing window events to enclosing app

Post by Victory »

We have a game that uses wxWxWidgets, which we want to release on Steam platform. As some of you might know, while running a game, if the user presses a chosen key combination (Shift+Tab, by default), Steam displays an overlay which allows the user to access some Steam community features.

Now, the problem is that pressing Shift+Tab does not bring up Steam overlay for our game. One guess I have is that all the key events must be going only to wxWidgets and Steam doesn't get them. Is there a way to make it so that the window key events not handled by our game can go to the enclosing app, i.e., Steam in this case?

Alternatively, if there is a way to make it so that the key events first go the enclosing application (Steam, in this case) before coming to our code, that is fine as well.

Any ideas/suggestions?

Thanks!
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Passing window events to enclosing app

Post by doublemax »

I guess the problem is that wxWidgets uses TAB and Shift-TAB to navigate between controls.

I don't know if that's enough, but the first thing i'd try is to override wxAppConsole::FilterEvent(), and if it's a keyboard event and TAB was pressed and shift is down, return 0.

https://docs.wxwidgets.org/trunk/classw ... c6f602e20c
https://docs.wxwidgets.org/trunk/classw ... ilter.html

I assume you checked all this?
https://partner.steamgames.com/doc/features/overlay
Use the source, Luke!
Victory
Earned some good credits
Earned some good credits
Posts: 115
Joined: Fri Mar 19, 2010 1:20 am

Re: Passing window events to enclosing app

Post by Victory »

Thanks "doublemax". When I try doing that, I am seeing something weird even without Steam integration. The following is my code. By putting breakpoints, I noticed that wxEVT_KEY_DOWN never arrived for any key I pressed! But, the mouse wheel event handled just above in the code does arrive. The break point on the line wxKeyEvent* pKeyEvent = wxDynamicCast(&event, wxKeyEvent) never got hit whatever key I pressed.

Code: Select all

int cApp::FilterEvent(wxEvent& event)
{
   wxEventType eventType = event.GetEventType();
   if (eventType == wxEVT_MOUSEWHEEL)
   {
      wxMouseEvent* pMouseEvent = wxDynamicCast(&event, wxMouseEvent);
      if (pMouseEvent)
      {
         // blah blah
         return wxEventFilter::Event_Processed;
      }
   }
   else if (eventType == wxEVT_KEY_DOWN)
   {
      wxKeyEvent* pKeyEvent = wxDynamicCast(&event, wxKeyEvent);
      if (pKeyEvent)
      {
         if (pKeyEvent->ShiftDown() && (pKeyEvent->GetKeyCode() == WXK_TAB))
         {
            return wxEventFilter::Event_Ignore;
         }
      }
   }

   return wxApp::FilterEvent(event);
}
I am using wxWidgets 3.1.1 on Windows 10.

Thanks.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Passing window events to enclosing app

Post by doublemax »

I tested this and i received wxEVT_CHAR_HOOK, wxEVT_KEY_DOWN and wxEVT_KEY_UP.

Is it possible you're using another library that consumes the event, e.g. SDL?
Try your code in a minimal sample and check if it works there.

Anyway, after reading the Steam docs, i don't really think that this mechanism requires the cooperation of the application. I'd assume that they use a keyboard hook, in which case it shouldn't matter if the application handles the event or not.
Use the source, Luke!
Victory
Earned some good credits
Earned some good credits
Posts: 115
Joined: Fri Mar 19, 2010 1:20 am

Re: Passing window events to enclosing app

Post by Victory »

No, I am not using SDL.
I made some progress on this. I found that the EVT_CHAR_HOOK handler was getting called before wxApp::FilterEvent and was consuming the key events. So, I removed that handler. I also decided to centralize the channeling of key events by removing the direct key event handlers in all places in our code and have all key events go through App::FilterEvent.With that, SHIFT-TAB does "normally" bring up the Steam overlay. But, the overlay fails to show up if some control (e.g., a button) other than our render window happens to have the focus. In such cases, the TAB key appears to be going to that control and doesn't arrive at App::FilterEvent. Is there any way to make the TAB key not go to other controls like that?

Thanks.
Post Reply