Jump to content

Current Window To Previous Window


Recommended Posts

Hi all.....

I am trying to use AutoItWinGetTitle to capture the current active window title, run a function which calls a new window active, and then return to the original window that was captured by AutoItWinGetTitle. So far this is what I have but it does not work:

Func RunNow()
$CurrentWin = AutoItWinGetTitle();**get title of current window**
If WinExists("Other Window") Then
Opt("WinWaitDelay",1)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("SendKeyDelay", 0)
WinWait("Other Window")
ProgressOn("Connecting!", "0 %")

For $i = 10 to 100 step 10
    sleep(50) 
    ProgressSet( $i, $i & " %") 
Next
ProgressSet(100 , "Done", "Complete") 
sleep(500) 
ProgressOff() 

WinWait("Other Window")
If Not WinActive("Other Window") Then WinActivate("Other Window")
WinWaitActive("Other Window")
Send("{ALTDOWN}TKUU")
Send("{ALTUP}")
WinActivate($CurrentWin);**focus back on original window that was active before function ran**
Else
    MsgBox(0, "Other Window - Error", "Cannot process request at this time. Please open Other Window and try again.")
EndIf

EndFunc

Any help is appreciated....thanks!

Link to comment
Share on other sites

As fare as my quick look could tell your code should work. Could you describe your broblem? What does not work as expected?

EDIT: You would probably have to tremove AutoIt from AutoItWinGetTitle as this returns the running scripts windowtitle and not the active windows title.

Edited by Uten
Link to comment
Share on other sites

As is, the function just jumps over to Other Window and runs the commands and then just stays there. I am trying to get it to jump back over to $CurrentWin after running through the commands......

Link to comment
Share on other sites

im workin on it now, but for one ur missing an EndIf in the function, 2 if statements but only 1 EndIf

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Link to comment
Share on other sites

;added this for testing
$other = "other window.txt - Notepad"

$CurrentWin = WinGetTitle("window1", "");**get title of current window**

If WinExists($other) Then
    Opt("WinWaitDelay",1)
    Opt("WinTitleMatchMode",4)
    Opt("WinDetectHiddenText",1)
    Opt("SendKeyDelay", 0)

    ProgressOn("Connecting!", "0 %")

    For $i = 10 to 100 step 10
        sleep(50)
        ProgressSet( $i, $i & " %")
    Next
    ProgressSet(100 , "Done", "Complete")
    sleep(500)
    ProgressOff()

    WinActivate($other)
    WinWaitActive($other)
    Send("{ALTDOWN}TKUU")
    Send("{ALTUP}")
    WinActivate($CurrentWin);**focus back on original window that was active before function 

ran**


Else
    MsgBox(0, "Other Window - Error", "Cannot process request at this time. Please open Other 

Window and try again.")
EndIf

EndFunc

this worked for me when i had 2 open text files, window1.txt and otherwindow.txt open in notepad.

lemme know how that works out

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Link to comment
Share on other sites

Also change the option from 4 to 2

(can match any part of title), unless the absolute title is necessary.

Opt("WinTitleMatchMode",2)

HardCopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Link to comment
Share on other sites

Ok...got it to work. Had to use $CurrentWin = WinGetTitle("") to make it run correctly...could not get it to go with "window1" in there. Now I am seeing a different problem.....once $CurrentWin is defined it holds that value and goes back to that window even if I start on a completely new window. Is there anyway to clear the $CurrentWin value so on next run it resets that value? Basically this code runs on a timer loop and I want it to go back to the last active window before last loop was run. Thanks........

Link to comment
Share on other sites

Is this what you mean, above post was a little confusing.

While 1

$currwin = WinGetTitle()

         ;Put timer loop code here

WEnd

This way if the timer loop ends and you have a new window active, it will get that new window and put that value in for $currwin.

Edited by Don N

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Link to comment
Share on other sites

Yes......Basically what happens is that it goes back to the orignial box registered as $CurrentWin = WinGetTitle("") the first time through. So lets give an example:

Box1 <--- Original Box

Box2 <--- Called Box

Box3 <--- Other Box

If I run the code with Box1 open it runs as planned and launches Box2 then switches focus back to Box1 - Good Stuff. Then on the next loop with Box3 open...it still goes back to Box1 as being the last active box. Is there a way to clear $CurrentWin so that on the next loop it is starting from blank?

Link to comment
Share on other sites

can u post ur new code here?

did my other post about putting the timer loop in the infinite while loop work, cuz that code would reset $currwin to the active window each time ur timer loop restarted

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Link to comment
Share on other sites

Func Processing()
Global $StartTime
Call("StartTimer")
While 1
  $CurrentWin = WinGetTitle("")
  $MPos1 = MouseGetPos()
  $CPos1 = WinGetCaretPos()
  Sleep(1000)
  $MPos2 = MouseGetPos()
  $CPos2 = WinGetCaretPos()

  If $MPos1[0] <> $MPos2[0] Then
    Call("StartTimer")
  ElseIf $CPos1[0] <> $CPos2[0] Then
    Call("StartTimer")
  EndIf

  $EndTime = TimerStop($StartTime)
  
  If $EndTime > 60000 Then
   

Opt("WinWaitDelay",1)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("SendKeyDelay", 0)
WinWait("Box2")

ProgressOn("", "Connecting"0 %")

For $i = 10 to 100 step 10
    sleep(50) 
    ProgressSet( $i, $i & " %") 
Next
ProgressSet(100 , "Done", "Complete") 
sleep(500) 
ProgressOff() 

WinWait("Box2")
If Not WinActive("Box2") Then WinActivate("Box2")
WinWaitActive("Box2")
Send("{ALTDOWN}TKUU")
Send("{ALTUP}")
WinActivate($CurrentWin)
Call("StartTimer")       
  EndIf

Wend
EndFunc
;###PROCESSING END###

Basically it waits for the computer to be idle for 1 minute then it fires off the WinActivate. But if I change windows after the first loop it always goes back to the original $CurrentWin. Thanks.........

Link to comment
Share on other sites

Func Processing()
Global $StartTime
Call("StartTimer")
While 1

  $MPos1 = MouseGetPos()
  $CPos1 = WinGetCaretPos()
  Sleep(1000)
  $MPos2 = MouseGetPos()
  $CPos2 = WinGetCaretPos()

  If $MPos1[0] <> $MPos2[0] Then
    Call("StartTimer")
  ElseIf $CPos1[0] <> $CPos2[0] Then
    Call("StartTimer")
  EndIf

  $EndTime = TimerStop($StartTime)
  
  If $EndTime > 60000 Then
   
;*************************************************
  $CurrentWin = WinGetTitle("")

Opt("WinWaitDelay",1)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("SendKeyDelay", 0)
WinWait("Box2")

ProgressOn("", "Connecting"0 %")

For $i = 10 to 100 step 10
    sleep(50) 
    ProgressSet( $i, $i & " %") 
Next
ProgressSet(100 , "Done", "Complete") 
sleep(500) 
ProgressOff() 

WinWait("Box2")
If Not WinActive("Box2") Then WinActivate("Box2")
WinWaitActive("Box2")
Send("{ALTDOWN}TKUU")
Send("{ALTUP}")
;################################################
WinActivate($CurrentWin)
Call("StartTimer")       
  EndIf

Wend
EndFunc
;###PROCESSING END###

check out the line under all the #'s...see the problem, u reactivate the first window so its always gonna be what is retrieved by wingettitle(), to get arround this place the WinGetTitle() in the spot where i put it, i put it under all the *'s.

this code will only get the active title after there is no activity for a minute, that way you will have time to change the active window before your loop gets the title again.

Hope this helps

Edited by Don N

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Link to comment
Share on other sites

Thanks for your help by the way..............

Seems to still not work for me for some strange reason. I even tried adding $CurrentWin = 0 to the loop as well but as long as that original window is open it always goes back to it. Maybe I will leave this feature out for this version :think:

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...