• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 823
  • Last Modified:

AutoIT execution problems

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
hrolsons
Asked:
hrolsons
  • 9
  • 6
  • 5
  • +1
2 Solutions
 
Kent DyerCommented:
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
 
hrolsonsAuthor Commented:
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
 
Kent DyerCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
hrolsonsAuthor Commented:
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
 
Kent DyerCommented:
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
 
hrolsonsAuthor Commented:
Yes, I'm in their forum discussing this same topic, but not getting anywhere.
0
 
pony10usCommented:
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
 
Kent DyerCommented:
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
 
matrixnzCommented:
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
 
hrolsonsAuthor Commented:
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
 
matrixnzCommented:
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
 
hrolsonsAuthor Commented:
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
 
matrixnzCommented:
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
 
hrolsonsAuthor Commented:
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
 
matrixnzCommented:
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
 
Kent DyerCommented:
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
 
hrolsonsAuthor Commented:
Entered your code and it reported sending the correct keys.
0
 
hrolsonsAuthor Commented:
My code works, it's just that I'd rather not use sleep.  But maybe I'll just leave well enough alone.
0
 
matrixnzCommented:
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
 
matrixnzCommented:
That was a complete waste of my time, can see why the AutoIT Forums didn't get far either.
0
 
hrolsonsAuthor Commented:
Your solution never worked.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 9
  • 6
  • 5
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now