AlexK Posted August 22, 2010 Share Posted August 22, 2010 Hi All,I have a script that is supposed to do a very simple operation: activate a particular window, open the edit box (Ctrl-E), select all (Ctrl-A), paste the clipboard contents (Ctrl-V), and press Escape.Opt("WinTitleMatchMode", 4) If WinActivate("[REGEXPTITLE:mydeck.+ - Anki]") <> 0 Then WinWaitActive("[REGEXPTITLE:mydeck.+ - Anki]","",4) If WinActive("[REGEXPTITLE:mydeck.+ - Anki]") <> 0 Then Sleep(100) Send("^e") Sleep(100) Send("^a") Sleep(100) Send("^v") Sleep(100) Send("{ESCAPE}") EndIf EndIfThe window title may vary - it may be "mydeck (25 items left) - Anki" or "mydeck* - Anki" but anyway the regex always matches and AutoIt does find it, because it always switches to that window reliably.However the problem is that after switching to the Anki window, 20% of the time AutoIt exits (the little tray icon disappears) without ever sending the keystrokes. I've tried putting in Sleep calls and other various stuff, but being a newbie at AutoIt couldn't find a reliable solution.It is run from a batch file with the lineAutoIt3.exe ankipaste.au3I was unable to find reliable repro steps; simply re-running the bat file has an ~80% chance of succeeding.Is there anything outwardly wrong with the script? Thank you very much. Link to comment Share on other sites More sharing options...
AlexK Posted August 22, 2010 Author Share Posted August 22, 2010 Sorry about the title; clicked Submit before editing it! Unfortunately I can't seem to be able to edit it now. It should read "Script to {switch to window and paste} aborts prematurely". Link to comment Share on other sites More sharing options...
omikron48 Posted August 22, 2010 Share Posted August 22, 2010 This Link to comment Share on other sites More sharing options...
AlexK Posted August 24, 2010 Author Share Posted August 24, 2010 Thank you omikron48! Unfortunately the particular fix you linked to didn't work directly; however it helped me figure out where to dig further. It turns out that putting a Sleep(200) right after WinActivate was enough to make sure AutoIt realizes it switched to the desired window correctly. I guess this is because, according to documentation, AutoIt makes six attempts during WinActivate, then gives up. The window in question being a Python application, maybe it is a little sluggish? So after switching to it maybe it wasn't responding quickly enough to AutoIt's "are you active now?" probing. In any case, thanks. Link to comment Share on other sites More sharing options...
omikron48 Posted August 24, 2010 Share Posted August 24, 2010 Yeah. There's also the case where the interface isn't ready to accept input the moment the window is active. I think that's what happened to you. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now