8

I'm mapping events coming from an external sensor (e.g. a keypad) to keyboard shortcuts and I would like to switch applications using the Fast switch overlay window ( i.e. Alt-Tab menu"), but I want to keep showing the switch menu until an application is chosen.

Basically, what am I doing is this :

if(notInSwitchMenu) 
{   // Alt-Tab keystroke, but Alt remains pressed : the menu is still visible
    Press(VK_MENU); 
    Press(VK_TAB); 
    Release(VK_TAB);
}
else
{

    if(event1) //Tab keystroke : next app
    {
        Press(VK_TAB);
        Release(VK_TAB) ;
    } 
    else if(event2) //Shift-Tab keystroke  : previous app
    { 
        Press(VK_SHIFT); 
        Press(VK_TAB);
        Release(VK_TAB);
        Release(VK_SHIFT) 
    }
    else if(event3) // we get out of the menu : the selected app has the focus.
    {
        Release(VK_MENU);
    } 
}

The Press and Release simply call SendInput with the right properties.

My problem is that I don't know a robust method to determine if the user is currently in the Alt-Tab program list. Do anyone know how to identify the Alt-Tab overlay menu with the Win32 API ?

NIMISHAN
  • 1,265
  • 4
  • 20
  • 29
lucasg
  • 10,734
  • 4
  • 35
  • 57

1 Answers1

9

The EVENT_SYSTEM_SWITCHSTART/EVENT_SYSTEM_SWITCHEND events tell you when the Alt+Tab window appears and disappears.

NIMISHAN
  • 1,265
  • 4
  • 20
  • 29
Raymond Chen
  • 44,448
  • 11
  • 96
  • 135
  • 1
    To elaborate, use [SetWinEventHook](http://msdn.microsoft.com/en-us/library/windows/desktop/dd373640.aspx) to receive these events. – Remy Lebeau Oct 13 '12 at 03:19
  • Can anyone attach an example? – yonni May 16 '22 at 14:18
  • @yonni as far as I know EVENT_SYSTEM_SWITCHSTART/EVENT_SYSTEM_SWITCHEND does not work correctly since Windows 10. You can try this solution instead https://stackoverflow.com/a/49597746/511801 – mattsson Dec 15 '22 at 11:03