3

In my app, I have a special action mapped to the tab key. The problem is that when you use the short-cut Alt-Tab to switch between different apps, my app gets a tab key (but not the Alt key) when it becomes activated, which I'd like to avoid. This happens sometimes (not all the time), especially when you switch apps very fast.

I could filter it out by checking Keyboard.IsKeyDown(Key.LeftAlt), but my app doesn't get the Alt-key in this case. Any tip?

newman
  • 6,841
  • 21
  • 79
  • 126
  • I think [Processing Global Mouse and Keyboard Hooks in C#](http://www.codeproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C) can help. – Ramin Dec 22 '12 at 09:10
  • 1
    Thanks for your tip, Ramin, but in general, I'd like to avoid Global Hook which may slow down the system a little bit, and some anti-virus programs even filter out the apps with global hook, as I read. – newman Dec 28 '12 at 16:26
  • Did you ever find a way to detect Alt and Tab when your program is activated via Alt-Tab? – Scott Solmer Jul 02 '14 at 12:54

1 Answers1

0

I've had an issue where KeyUp event handler doesn't register e.Key == Key.LeftAlt. Instead I had to use e.SystemKey == Key.LeftAlt. Perhaps you are facing a similar issue (although I don't know if you use the KeyUp/KeyDown event handler)?

Another thing to try would be Keyboard.Modifiers == ModifierKeys.Alt or maybe even KeyboardDevice.Modifiers == ModifierKeys.Alt inorder to filter out Alt.

Marko
  • 2,266
  • 4
  • 27
  • 48