Advertisement
anonymous1184

xRun()

Jan 23rd, 2021
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. xRun(target, title := "", mode := 11, sendKey := false)
  2. {
  3.     if wID := WinExist(title)
  4.     {
  5.         wID := "ahk_id " wID
  6.         WinGet, wStyle, Style
  7.         if (wStyle = 0x06CF0000) ; isTray
  8.         {
  9.             WinGetClass, wClass
  10.             WinShow, % "ahk_class " wClass
  11.         }
  12.         else if (wStyle = 0x94000102) ; isMinimized
  13.         {
  14.             PostMessage, 0x112, 0xF120,,, % wID  ; 0x112 = WM_SYSCOMMAND, 0xF120 = SC_RESTORE
  15.         }
  16.         WinActivate
  17.         return
  18.     }
  19.  
  20.     if (RegExMatch(target, "^\\\w"))
  21.     {
  22.         target := A_ScriptDrive target
  23.     }
  24.  
  25.     if (WinExist("ahk_exe " target) && sendKey)
  26.     {
  27.         Send, % sendKey
  28.         return
  29.     }
  30.  
  31.     modeLen := StrLen(mode)
  32.     if (!modeLen)
  33.     {
  34.         m1 := 1
  35.         , m2 := 1
  36.     }
  37.     else if (modeLen = 1)
  38.     {
  39.         m1 := mode
  40.         , m2 := 1
  41.     }
  42.     else
  43.     {
  44.         RegExMatch(mode, "(.)(.)", m) ; for the lolz
  45.     }
  46.  
  47.     if (m1 = 2)
  48.     {
  49.         target := "*RunAs " target
  50.     }
  51.     else if (m1 = 3)
  52.     {
  53.         target := "path\to\PowerRun.exe """ target """"
  54.     }
  55.  
  56.     switch m2
  57.     {
  58.         case 0: mode := "Hide"
  59.         case 1: mode := "" ; Normal
  60.         case 2: mode := "Min"
  61.         case 3: mode := "Max"
  62.     }
  63.  
  64.     Run, % target,, % mode " UseErrorLevel", pid
  65.     WinWait, % "ahk_pid " pid,, 3
  66.     WinActivate, % "ahk_pid " pid
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement