Sign in to follow this  
Followers 0
CassidyHunt

Sub Screen not keeping focus

5 posts in this topic

I have a script that opens a program then opens another program from a menu in the first program. When the new window opens it immediatly loses focus and goes back to the first program. I can't figure out why.

Here is the script:

Opt("WinWaitDelay",100)

Opt("WinTitleMatchMode",4)

Opt("WinDetectHiddenText",1)

Opt("MouseCoordMode",0)

Run('\\pandora\visual\ve652\vmfg\VM.EXE')

WinWait("VISUAL Enterprise - VMFG/SYSADM","")

If Not WinActive("VISUAL Enterprise - VMFG/SYSADM","") Then WinActivate("VISUAL Enterprise - VMFG/SYSADM","")

WinWaitActive("VISUAL Enterprise - VMFG/SYSADM","")

Send("{ALTDOWN}{ALTUP}gu")

WinWait("Costing Utilities","")

If Not WinActive("Costing Utilities","") Then WinActivate("Costing Utilities","")

WinWaitActive("Costing Utilities","")

Thanks in advance for any of your help.

Cassidy

Share this post


Link to post
Share on other sites



I have a script that opens a program then opens another program from a menu in the first program. When the new window opens it immediatly loses focus and goes back to the first program. I can't figure out why.

Here is the script:

Opt("WinWaitDelay",100)

Opt("WinTitleMatchMode",4)

Opt("WinDetectHiddenText",1)

Opt("MouseCoordMode",0)

Run('\\pandora\visual\ve652\vmfg\VM.EXE')

WinWait("VISUAL Enterprise - VMFG/SYSADM","")

If Not WinActive("VISUAL Enterprise - VMFG/SYSADM","") Then WinActivate("VISUAL Enterprise - VMFG/SYSADM","")

WinWaitActive("VISUAL Enterprise - VMFG/SYSADM","")

Send("{ALTDOWN}{ALTUP}gu")

WinWait("Costing Utilities","")

If Not WinActive("Costing Utilities","") Then WinActivate("Costing Utilities","")

WinWaitActive("Costing Utilities","")

Thanks in advance for any of your help.

Cassidy

Not quite enough information for me to decide what you need, but I would try adding a delay after WinWait("Costing Utilities","") because I think I've had problems waiting for a window to exist and then doing something. Maybe the window exists before it is actually drawn and so it can't be activated.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Worked perfect. I added sleep(100) and now it works.

Thanks

Cassidy

Share this post


Link to post
Share on other sites

Worked perfect. I added sleep(100) and now it works.

Thanks

Cassidy

Glad that worked.

On reflection it might need a longer delay sometimes depending on the gui and what windows is also trying to do, so it might have been better to have something like this

WinWait("Costing Utilities","")

$try = 0
while $try < 50 and not  WinActivate("Costing Utilities","")
 sleep(100)
 $try += 1
wend

if $try > 49 then $Allgonewrong = true

I haven't tried this and I'm assuming that when your code failed WinActivate would have returned 0.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Glad that worked.

On reflection it might need a longer delay sometimes depending on the gui and what windows is also trying to do, so it might have been better to have something like this

WinWait("Costing Utilities","")

$try = 0
while $try < 50 and not  WinActivate("Costing Utilities","")
 sleep(100)
 $try += 1
wend

if $try > 49 then $Allgonewrong = true

I haven't tried this and I'm assuming that when your code failed WinActivate would have returned 0.

Good idea. I do have one more question. Is there way to check if the program is already open?

Share this post


Link to post
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
Sign in to follow this  
Followers 0