Advertisement
somdcomputerguy

AutoGAT++

Nov 14th, 2023 (edited)
1,713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 3.94 KB | Source Code | 0 0
  1. Opt("TrayMenuMode", 3)
  2. Opt("WinTitleMatchMode", 2) ; 1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
  3. Opt("WinDetectHiddenText", 1) ; 0=don't detect, 1=do detect
  4.  
  5. Local $SleepTime   = 100
  6. Local $KeePass[2]  = ["C:\Program Files\KeePass Password Safe 2\", "KeePass.exe"]
  7.  
  8. If $CmdLine[0] > 1 Then
  9.  For $i = 1 to $CmdLine[0]
  10.   Switch $CmdLine[$i]
  11.    Case '-delay'
  12.     $SleepTime  = $CmdLine[$i + 1]
  13.    Case '-path'
  14.     $KeePass[0] = $CmdLine[$i + 1]
  15.    Case '-name'
  16.     $KeePass[1] = $CmdLine[$i + 1]
  17.   EndSwitch
  18.  Next
  19. EndIf
  20.  
  21. Local $helpURL     = "https://keepass.info/help/base/index.html"
  22. Local $AutoType[6] = ["-auto-type", "-auto-type-password", "-auto-type-selected", "--lock-all", "--unlock-all", "--exit-all"]
  23.  
  24. Local $idKPsf = TrayCreateMenu("KeePass Password Safe")
  25. Local $idKP   = TrayCreateItem("KeePass", $idKPsf)
  26. Local $idKPH  = TrayCreateItem("KeePass Help", $idKPsf)
  27. Local $idQUIT = TrayCreateItem("Exit KeePass", $idKPsf)
  28.  TrayCreateItem("")
  29. Local $idTOGL = TrayCreateItem("Lock or Unlock database")
  30. Local $idAT   = TrayCreateItem("AutoType Selected")
  31. Local $idGAT  = TrayCreateItem("Global AutoType")
  32. Local $idGATP = TrayCreateItem("Global PassWord")
  33.  TrayCreateItem("")
  34. Local $idAG   = TrayCreateMenu("AutoGAT++")
  35. Local $idRest = TrayCreateItem("Restart", $idAG) ; don't really need to use this anymore, but..
  36. Local $idExit = TrayCreateItem("Terminate", $idAG)
  37.  
  38. TraySetState(1)
  39.  
  40. While 1
  41.  If Not ProcessExists($KeePass[1]) Then ExitLoop ;leaves this While loop if KeePass exits or isn't running
  42.  If WinGetTitle("Locked") Then
  43.   TraySetToolTip("AutoGAT++   database locked")
  44.   TraySetIcon(@ScriptDir & '\AutoGAT_locked.ico')
  45.   TrayItemSetState($idAT, 128) ;Menuitem will be greyed out
  46.   TrayItemSetState($idGAT, 128) ;Menuitem will be greyed out
  47.   TrayItemSetState($idGATP, 128) ;Menuitem will be greyed out
  48.   TrayItemSetText($idTOGL, "Unlock database")
  49.  Else
  50.   TraySetToolTip("AutoGAT++")
  51.   TraySetIcon(@ScriptDir & '\AutoGAT.ico')
  52.   TrayItemSetState($idAT, 64) ;Menuitem will be enabled
  53.   TrayItemSetState($idGAT, 64) ;Menuitem will be enabled
  54.   TrayItemSetState($idGATP, 64) ;Menuitem will be enabled
  55.   TrayItemSetText($idTOGL, "Lock database")
  56.  EndIf
  57.  
  58.  Switch TrayGetMsg()
  59.   Case -13 ;$TRAY_EVENT_PRIMARYDOUBLE
  60.    ShellExecute($KeePass[0] & $KeePass[1])
  61.   Case $idRest ; don't really need to use this anymore either, but..
  62.    Restart()
  63.   Case $idExit
  64.    ExitLoop
  65.   Case $idKP
  66.    ShellExecute($KeePass[0] & $KeePass[1])
  67.   Case $idKPH
  68.    ShellExecute($helpURL)
  69.   Case $idAT
  70.    Send("!{TAB}")
  71.    Sleep($SleepTime)
  72.    ShellExecute($KeePass[0] & $KeePass[1], $AutoType[2])
  73.   Case $idGAT
  74.    Send("!{TAB}")
  75.    Sleep($SleepTime)
  76.    ShellExecute($KeePass[0] & $KeePass[1], $AutoType[0])
  77.   Case $idGATP
  78.    Send("!{TAB}")
  79.    Sleep($SleepTime)
  80.    ShellExecute($KeePass[0] & $KeePass[1], $AutoType[1])
  81.   Case $idTOGL
  82.    If TrayItemGetText($idTOGL) = "Unlock database" Then
  83.     TraySetIcon(@ScriptDir & '\AutoGAT_locked.ico')
  84.     TrayItemSetState($idAT, 64) ;Menuitem will be enabled
  85.     TrayItemSetState($idGAT, 64) ;Menuitem will be enabled
  86.     TrayItemSetState($idGATP, 64) ;Menuitem will be enabled
  87.     ShellExecute($KeePass[0] & $KeePass[1], $AutoType[4]) ; Unlock
  88.    Else
  89.     TraySetIcon(@ScriptDir & '\AutoGAT.ico')
  90.     TrayItemSetState($idAT, 128) ;Menuitem will be greyed out
  91.     TrayItemSetState($idGAT, 128) ;Menuitem will be greyed out
  92.     TrayItemSetState($idGATP, 128) ;Menuitem will be greyed out
  93.     ShellExecute($KeePass[0] & $KeePass[1], $AutoType[3]) ; Lock
  94.    EndIf
  95.   Case $idQUIT
  96.    ShellExecute($KeePass[0] & $KeePass[1], $AutoType[5])
  97.  EndSwitch
  98. WEnd
  99.  
  100. Exit
  101.  
  102. Func Restart()
  103. ; Restart your program - http://www.autoitscript.com/forum/index.php?s=&showtopic=19370&view=findpost&p=199608
  104. ; Author UP_NORTH
  105.     If @Compiled = 1 Then
  106.         Run(FileGetShortName(@ScriptFullPath))
  107.     Else
  108.         Run(FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath))
  109.     EndIf
  110.     Exit
  111. EndFunc     ;==>Restart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement