tags:

views:

159

answers:

1

After playing quite a bit of Bad Company 2 over the last month, I'm getting kind of tired of Alt+Tabbing out of my game to change the song on iTunes. I've got a fairly good iTunes controller library already built for a previous project I was working on, and I'd like to create a WPF application mimicking the BC2 UI that would overlay the game when pressing a shortcut key, much the same way as the Steam Community overlay.

The only problem I foresee is getting my application to overlay BC2 when the user presses a specified shortcut key in-game. Is there a way to intercept a keypress from BC2 (or, really, any Win32 application) and use it to bring my app to the foreground?

+2  A: 

In order to have a global keyboard shortcut, you need to use a Hook.

Here is a tutorial showing how to do Keyboard Hooks in C#.

That being said, doing the overlay may be difficult, depending on how the game is written. Many full screen games cannot (easily) have other programs run in front of them. I'd play with making sure that works correctly in your specific game first.

Reed Copsey
Wow. That was fast. Probably should have tried to Google a bit more... That said, it looks like there's ways to overlay on games, at least there was using Managed DirectX. Hopefully I can figure out a WPF equivalent :)
Eric Smith
What you're wanting to do is definitely doable: http://www.playxpert.com/web/guest/homeI'm pretty sure they used WPF for their product.
JohnForDummies
Yeah, I've got keyboard hooks working just fine. It's getting my app to overlay the DirectX game that's the problem. If I try this.Activate() or set the WindowState to Normal (from minimized) when the key is pressed, nothing happens when I'm in the game. There's practically nothing online about overlaying fullscreen DX apps with WPF windows.
Eric Smith
Turns out the real problem is the keyboard hook not detecting the keypress when the DirectX app has focus. Somehow the DX app is blocking it.
Eric Smith