Jump to content

Avoid loosing focus


Jango
 Share

Recommended Posts

Hello,

I use the following script to send user and password to an application and it works. The shortcut is in the quick launch bar (one click). But, some users do a double click in the quick launch bar and then my script fail because the window looses focus even if i put a WinActivate just before sending user/pwd. Any help is welcome.

$Start = TimerInit()

While 1
    If TimerDiff($Start) > $TimeOut Then ExitLoop
    If WinExists($Title) Then
        WinActivate($Title)
        Send($User)
        Send("{TAB}")
        Send($Pwd)
        Send("{ENTER}")
        ExitLoop
    EndIf
    Sleep(100)
WEnd
Link to comment
Share on other sites

$Start = TimerInit()

While 1
    If TimerDiff($Start) >= $TimeOut Then ExitLoop
    If WinExists($Title) Then
        WinActivate($Title)
        Sleep(500);allow the program focus to take effect
        Send($User)
        Send("{TAB}")
        Sleep(500);wait to make sure the control has registered
        Send($Pwd)
        Send("{ENTER}")
        ExitLoop
    EndIf
    Sleep(100)
WEnd
I'd also recommend you use ControlSend() and not just Send/tab/etc. That way the controls will get the data even if the window doesn't have the focus, you don't need to tab, and you can ControlClick() the send/enter/next button.

Link to comment
Share on other sites

Use a ControlSend() function.

Hi there,

Or you can add _Singleton to your script and keep it smooth to run only one instance of your script.

Cheers

Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Link to comment
Share on other sites

From what I read the problem is the event is triggered by a single click but when a person double clicks it takes focus away from the control/program being manipulated and sets focus to the tray icon so I don't see how _Singleton would help.

Link to comment
Share on other sites

From what I read the problem is the event is triggered by a single click but when a person double clicks it takes focus away from the control/program being manipulated and sets focus to the tray icon so I don't see how _Singleton would help.

Correct. thank you for your help.

Link to comment
Share on other sites

Also look at SendKeepActive() - Attempts to keep a specified window active during Send().

It's relatively new AutoIt's native function introduced in version 3.2.10.0 (25th November, 2007)

Here is my code corrected :

$Start = TimerInit()

While 1
    If TimerDiff($Start) > $TimeOut Then ExitLoop
    If WinExists($Title) Then
        $Handle = WinGetHandle($Title)
        ControlSend($Handle, "", "Edit2", $User)
        ControlSend($Handle, "", "Edit3", $Pwd)
        ControlClick($Handle, "OK", "Button1")
        ExitLoop
    EndIf
    Sleep(100)
WEnd
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...