Solved

AutoIT execution problems

Posted on 2014-02-07
21
716 Views
Last Modified: 2014-02-13
I have a little code to manipulate .jpg files.  The code is not allowing the previous instructions to finish.  I tried:
	Send("!I")
	Send("E")
	Send("6")
	WinWaitActive("Resize")
	Send("+R")
	WinWaitActive("Resize")
        Send("+S")

Open in new window

And it only executes the first 3 key presses.

I've tried:
	Send("!I")
	Send("E")
	Send("6")
	sleep(5000)
	Send("+R")
	sleep(5000)
        Send("+S")

Open in new window

And this is very slow for some images and not slow enough for larger images.

Any ideas?
0
Comment
Question by:hrolsons
  • 9
  • 6
  • 5
  • +1
21 Comments
 
LVL 17

Assisted Solution

by:Kent Dyer
Kent Dyer earned 500 total points
ID: 39842293
Here is an idea,,  Why not add in sleep states between steps?

If you can use the WinWait or state checks in AutoIT, you will do better than implementing sleep..  I know that is kind of contradictory to what I just stated.  LOL!..  Just thinking here a bit..  What is the application you are trying to automatically run?  Irfanview?  MS Paint?  Maybe if you presented it that way, there maybe a better way to do what you are looking for?  Most of the time, folks are looking either to re-size width x height or to compress the size of the graphic..
0
 

Author Comment

by:hrolsons
ID: 39842318
I'm using Paint Shop Pro v8.1.  The above code:
 
1. Changes the image to 16 million colors.
2. Crops to what is selected.
3. Opens the Resize window.
0
 
LVL 17

Accepted Solution

by:
Kent Dyer earned 500 total points
ID: 39842356
Does PSP 8.1 have macros?  I just googled and version 12 does have them..  I know AutoIT and KiXtart do allow the use of keypress and AutoIT has mouse movements too..  Also, VBScript has some key press functions too..  But, if you can do this as a macro in PSP, you will do way better than any external app/script that does the keypress/mouse movement will.  :)
0
 

Author Comment

by:hrolsons
ID: 39842423
Yes, it does have macros.  I didn't use them for 2 reasons.  There is not much documentation, and I wanted to learn AutoIT so that I could use it for other applications.
0
 
LVL 17

Expert Comment

by:Kent Dyer
ID: 39842493
At the risk of having my hand slapped here by the Moderator.  :)  You do realize that AutoIT has a very active discussion forum?  There is also AutoIT's sister product called AutoHotKey too..
0
 

Author Comment

by:hrolsons
ID: 39842512
Yes, I'm in their forum discussing this same topic, but not getting anywhere.
0
 
LVL 26

Expert Comment

by:pony10us
ID: 39842546
Maybe instead of sleep() you could use ProcessExist()?

I think the process is "Corel PaintShop Pro.exe"

so

Do
      $process = ProcessExists("Corel PaintShop pro.exe")
Until $process = 0 ; Until process is gone
0
 
LVL 17

Expert Comment

by:Kent Dyer
ID: 39842568
Also remembering back to my days of Application support with Disabled folks, you should be able to get to menus and such using SHIFT+F10, ALT+SPACEBAR, etc. too.  YMMV.
0
 
LVL 29

Expert Comment

by:matrixnz
ID: 39844026
Can you use the "AutoIT Window Info Tool" on the "Resize" Window and send through a screenshot of the results?

Example:
WinWaitActive Example
Sorry don't have PaintShop Pro, so have used FireWorks as an example, using the code below, I can detect based on the Title, Class and Instance and also only when that Instance has the text "Resize" in its name.  You can gather that information using the AutoIt Window Info tool as shown above.  Hope that makes sense.

WinWaitActive('[TITLE:Numeric Transform; CLASS:#32770; INSTANCE:1]', 'Resize')

Open in new window

0
 

Author Comment

by:hrolsons
ID: 39844303
I was wrong in my original code because "Resize" isn't even open until the last "Send" command.  But I tried WinWait("Jasc Paint Shop Pro") and it didn't work.

Here is the screenshot that you requested:

Screenshot
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 29

Expert Comment

by:matrixnz
ID: 39844441
Couple of questions:
So what does the Shift + R do?
Are you able to send me an example Image and specify exactly what you want it to do?

Have found an old copy of Jasc Paint Shop Pro 8.1 so can test, but would need exact instructions, before and after Resize command.

Personally, I don't like send commands, since the scripts can easily be broken by simply clicking the mouse off screen or pressing a key on your keyboard.  Using a combination of the Jasc Script Tool and Batch Processing you can basically perform the actions on an entire directory easily without much trouble (see info below).  However with that being said, there are some ways to actively force send keys, i.e. using combinations of WinActivate and WinWaitActive, so can show a few ways if you still want to go down that track.


Jasc Script Tool
 - File » Script » Start Recording
Batch Processing
 - File » Batch » Process...
0
 

Author Comment

by:hrolsons
ID: 39844749
Shift + R crops to selection.

Here is the code sequence:

I've gotten my picture up and I've selected the crop I want and press F7:

1. Crops to my selection
2. Changes to 16 million colors
3. Change Resolution to 100 pixels/inch
4. Resize setting whatever is smaller, height or width, to 4000.
5. Sharpen More
6. Sharpen More

Here is the code as it stands:

HotKeySet("{F7}", "size")

 While 1
    Sleep(100)
 WEnd

Func size()
	Send("!i")
	Send("e")
	Send("6")
	sleep("3000")
	Send("+r")
	sleep("3000")
    Send("+s")
    WinWaitActive("Resize")
    $resolution = ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:5]");reads the current resolution, change resolution with the correct control
	If $resolution <> "100.000" Then 
		ControlSetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:5]", "100");set the resolution control, change resolution with the correct control
	Endif
	$width= ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:1]");reads the current width, change width with the correct control
    $height= ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:2]");reads the current height, change height with the correct control
	$height=$height+1;
	$width=$width+1
	sleep("1000")
    If $width<$height Then; compare the 2
        ControlSetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:1]", "4000");set the width control, change width with the correct control
    Else
        ControlSetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:2]", "4000");set the height control, change height with the correct control
    EndIf
	ControlClick("Resize", "", "[CLASS:Button; INSTANCE:14]")
	sleep("2000")	
	Send("!a")
	Send("s")
	Send("h")
	sleep("2000")	
	Send("!a")
	Send("s")
	Send("h")
EndFunc

Open in new window

0
 
LVL 29

Expert Comment

by:matrixnz
ID: 39844924
Can you please try the following, on my system I had to change the focus from Per Cent to Pixels before changing the Height and Width.  Pausing for 150ms between Send worked for me, you can of course change it higher/lower within the SendKey Function.

HotKeySet("{F7}", "size")

 While 1
    Sleep(100)
 WEnd

Func size()
	SendKey("!i")
	SendKey("e")
	SendKey("6")
	SendKey("+r")
    SendKey("+s")
    WinWaitActive("[TITLE:Resize; CLASS:#32770]", '')
    $resolution = ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:5]");reads the current resolution, change resolution with the correct control
	If $resolution <> "100.000" Then
		ControlSetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:5]", "100");set the resolution control, change resolution with the correct control
	Endif
	ControlFocus("Resize", "", "[CLASS:ComboBox; INSTANCE:1]")
	SendKey('Pixels')
	$width= ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:1]");reads the current width, change width with the correct control
    $height= ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:2]");reads the current height, change height with the correct control
	$height=$height+1;
	$width=$width+1
    If $width<$height Then; compare the 2
        ControlSetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:1]", "4000");set the width control, change width with the correct control
    Else
        ControlSetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:2]", "4000");set the height control, change height with the correct control
    EndIf
	ControlClick("Resize", "", "[CLASS:Button; INSTANCE:14]")
	SendKey("!a")
	SendKey("s")
	SendKey("h")
	SendKey("!a")
	SendKey("s")
	SendKey("h")
EndFunc

Func SendKey($SENDKEY, $TIME = 150)
	Send($SENDKEY)
	Sleep($TIME)
EndFunc

Open in new window

0
 

Author Comment

by:hrolsons
ID: 39845549
Tried and it only changed to 16 million and skipped the rest of the code.  Changed from 150 to 250 and it beeped and flashed and ran out of memory.
0
 
LVL 29

Expert Comment

by:matrixnz
ID: 39845637
Can you place the following at the top of your script:
;~ To turn off debugging just change $DEBUG = 0.
Global $DEBUG = 1

Then modify the SendKey function as follows:
Func SendKey($SENDKEY, $TIME = 150)
      Send($SENDKEY)
      Sleep($TIME)
      If $DEBUG = 1 Then MsgBox(64, 'Debug - SendKey Function', 'SendKey: ' & $SENDKEY, 3)
EndFunc

Unfortunately all the tests I've done, I wasn't able to reproduce the error at 150ms, although PaintShop Pro 8.1 was installed on a new Window 7 x64, computer with 8GB ram that was sitting in my office.  Please note I also got the memory error, but that was because as mentioned above, the default setting for me was "Per cent" rather than "Pixels", so it was attempting to resize the image by 879% the highest value, which understandably caused the memory error.  Maybe your machine is changing to Per Cent rather than Pixels?  Also all the images I had were already 16 million colours couldn't find any in my collection that wasn't, was using large 3995 x 3995 image as well.
0
 
LVL 17

Expert Comment

by:Kent Dyer
ID: 39845779
There is a very cool AutoIT forms editor that is available called Koda..  Most of the pages are in Russian, but the program does indeed support English..  Very cool and insightful for coding up things like this.  Have also used AdminScriptEditor even though they just went out of business..
0
 

Author Comment

by:hrolsons
ID: 39845988
Entered your code and it reported sending the correct keys.
0
 

Author Comment

by:hrolsons
ID: 39846166
My code works, it's just that I'd rather not use sleep.  But maybe I'll just leave well enough alone.
0
 
LVL 29

Expert Comment

by:matrixnz
ID: 39846205
If thats the case remove the two lines:
      ControlFocus("Resize", "", "[CLASS:ComboBox; INSTANCE:1]")
      SendKey('Pixels')
Change it to 250ms or 500ms and try again
0
 
LVL 29

Expert Comment

by:matrixnz
ID: 39857671
That was a complete waste of my time, can see why the AutoIT Forums didn't get far either.
0
 

Author Comment

by:hrolsons
ID: 39857767
Your solution never worked.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now