Search Unity

Switching between applications like alt+tab?

Discussion in 'Scripting' started by MikkoK-HS, Nov 23, 2017.

  1. MikkoK-HS

    MikkoK-HS

    Joined:
    Sep 26, 2017
    Posts:
    53
    I have a menu application that launches other unity applications. I'm trying to create a script that automatically "alt+tabs" out of the menu to the started application if the menu is opened while the other application is running. I've tried c#'s SwitchToThisWindow, ShowWindow and SetForegroundWindow, but none of them seem to do anything. Any pointers?

    Here's what I'm currently doing:
    Code (CSharp):
    1. private static void ChangeFocus(Process pr)
    2. {
    3.     System.IntPtr hWnd;
    4.     hWnd = pr.MainWindowHandle;
    5.     SwitchToThisWindow(hWnd, true);
    6.     ShowWindow(hWnd, 3);
    7.     SetForegroundWindow(hWnd);
    8. }
    The function is called when the other process is running and the menu application gets focus (OnApplicationFocus).
     
  2. MikkoK-HS

    MikkoK-HS

    Joined:
    Sep 26, 2017
    Posts:
    53
    Seems that Process.Responding is always false for a unity application. Is this normal?
     
  3. cshovan_nawctsd

    cshovan_nawctsd

    Joined:
    Mar 16, 2020
    Posts:
    2
    did you ever find a solution for this?

    currently seeing the same result for built application. setforegroundwindow seems to do nothing.