Get previous active window (not current)

Recommended Posts

badapple89 1

badapple89 1

Writing another script again to help out my "lovely" staff. But need some help.

Current Issue:

We open different format docs word, excel, adobe etc

When users press print they are presented with a popup (its actually a program [CLASS:#32770])

They must then type a matter number that this doc reffers to into this pop up so they can bill for the printing.

What I want:

Type the matter number in automatically when the popup appears.

The scripts so Far:

Get title from document

Strip down title to just the document number

Lookup a temp file (created by our doc management program) and get matter number out of it.

The issue:

My script currently only gets the matter number from a document when hotkey is pressed as im still testing.

But should I run the GetMatter function every time a window changes? and winwait for the popup to then type in the number? (not sure how to do the first bit)

But Would that use a lot of processing power?

If that isn't a good option could I winwait for the popup then somehow switch back to the LAST active window and get the title?

Thanks for any help and hope my question isnt to confusing

Here is my current code for testing.

;Gets title of current open window;Trims down title to get doc Number;Gets matter number from prf File;TO DO - Send matter number to equitrack when pop occurs;Run only one version of script#include <Misc.au3>_Singleton("EqFiller");Hotkeys used for testingHotKeySet("!d","GetMatter")HotKeySet("{ESC}","Terminate")HotKeySet("!f","Check");Global $matternum;~ If not WinActivate ("[CLASS:#32770]") Then;~ GetMatter ();~ ElseIf WinActivate ("[CLASS:#32770]") Then;~ MsgBox (0,"MatterNum", $matternum);~ EndifWhile1Sleep(100)WEndFunc GetMatter ();Location of checked out docs$temppath="C:\NRPortbl\matters\"&@UserName;Get title of current window so we can find doc number;Might need to change as eqtrack would be current open window$title=WinGetTitle("[CLASS:OpusApp]");Active Window;WinSetState ("[CLASS:#32770]","",@SW_Hide)$active=WinGetTitle("");AcrobatSDIWindow;XLMAIN;Find position of hash sign in window title as doc number follows this$Start=StringInStr($title,"#");Trim the window title from the hash sign (plus one character over) and for 8 characters long$tempdocnum=StringMid($title,$Start+1,8);Convert v1 or v2 (versions) to _1 or _2$docnum=StringReplace($tempdocnum,"v","_");Testing;MsgBox(0, "Full title read was:", $active & @LF & $title & @lf & $start & @lf & $tempdocnum & @lf & $docnum);Open loked file (prf) using doc number$locfile=FileOpen($temppath&"\"&$docnum&".prf");Read line 18 (should contain matter number)$tempMatter=FileReadLine($locfile,18);Trim the words off the start so we just endup with matter Number$Matternum=StringTrimLeft($tempMatter,7);Testing;MsgBox (0,"Matter number from PRF file", $tempMatter & @lf & $matternum);Close FileFileClose($locfile)MsgBox(0,"MatterNum",$matternum);WinSetState ("[CLASS:#32770]","",@SW_SHOW )EndFuncFunc Terminate()Exit0EndFunc;==>TerminateFunc Check()$title=WinGetTitle("[CLASS:OpusApp]")$state=WinGetState($title)$active=WinGetTitle("")$activestate=WinGetState("$active")MsgBox(0,"","Title="&$title&@lf&"State="&$state&@lf&"Active title="&$active&@lf&"Active State="&$activestate)EndFunc