Question

I'm not sure exactly how to start this project, but my requirements are as follows (for the parts that I'm unsure of how to implement):

  • Holding down the Tab key should display the overlay. Letting go of the tab key should hide the overlay. How would I capture this globally? What's the best way to check that the Tab key is still being held down?
  • The overlay should display over all other applications. It does not have to display over a full screened application, but it would be optimal to be able to do so.
  • Resolution scaling? Not as important, but it would be nice to have the size of the overlay scale based on the user's monitor resolution.

I haven't started this yet, but which project type would be best for this? I was thinking WPF over WindowsForms since it seems to offer a lot more flexibility in terms of presentation. Any advice on the above points would be greatly appreciated!

Was it helpful?

Solution

In WPF, you can do it this way:

For the global TAB key handling, at the entry point of your application (usually App.xaml.cs), run this code:

EventManager.RegisterClassHandler(typeof(UIElement), UIElement.PreviewKeyUpEvent, new KeyEventHandler(OnPreviewKeyUp));

Use (Preview)Key(up/Down)Event as you need it, if you set e.Handled = true in a Preview event handler, the event will stop its routing and nobody else will be able to react to it.

In OnPreviewKeyUp, check that e.Key == Key.Tab, and show the overlay window if it is.


The signature of the event handler should look like:

private static void OnPreviewKeyUp(object source, KeyEventArgs e)


Now for the click-through part, make a Window and set the background of your overlay to null:

WindowStyle="None" AllowsTransparency="True" Background="{x:Null}"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top