Olson Posted February 7, 2014 Share Posted February 7, 2014 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") 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") And this is very slow for some images and not slow enough for larger images. Any ideas? Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 7, 2014 Moderators Share Posted February 7, 2014 Instead of a long sleep, have you tried much shorter sleeps between each step? Without seeing precisely what you're doing with the file, or in what app, it is difficult to offer suggestions. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Olson Posted February 7, 2014 Author Share Posted February 7, 2014 Yes, I have tried shorter sleeps and it still skips over the next code if it's not ready. 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. Just telling you that helps me with one thing. WinWaitActive("Resize") doesn't work in the first 2 because "Resize" isn't open yet. I guess I would need to do WinWaitActive ("Jasc Paint Shop Pro") Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 7, 2014 Moderators Share Posted February 7, 2014 WinWaitActive means you're waiting until that window is present and has focus. If you just want to wait until the window exists, just use WinWait. It looks like you're running into problems because PSP takes a while to convert the image to 16 million colors. I would look into whether it spawns another process to make this conversion; then you could wait for the process to close. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
jdelaney Posted February 7, 2014 Share Posted February 7, 2014 Use the win*, and control* functions (look in the help file). They will be much more reliable, accurate, and timely than sends and sleeps. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Olson Posted February 7, 2014 Author Share Posted February 7, 2014 I just don't know what to wait for or what control to look at. For instance, if I'm changing the amount of colors from 256 to 16 million, the program "thinks" for a few seconds while doing this. I looked at the processes in Task Manager and I didn't see a new one pop up while the program is processing the instructions. Link to comment Share on other sites More sharing options...
jdelaney Posted February 7, 2014 Share Posted February 7, 2014 When it's 'thinking' the window state will change to NOT include 'enabled'. Look into wingetstate IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Olson Posted February 7, 2014 Author Share Posted February 7, 2014 WinGetState seems to be 47 always, whether it's "thinking" or not. Link to comment Share on other sites More sharing options...
jdelaney Posted February 7, 2014 Share Posted February 7, 2014 Something must change on the gui. How do you, as an observer, know it's done? What is the code you were using to get the wingetstate? What is the code you were using to search for the other processes? You can also use this function, to see if any new handles are produced (would need to run ALL these options in loops).._WinAPI_EnumProcessWindows($iPid) IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
nullschritt Posted February 7, 2014 Share Posted February 7, 2014 I just don't know what to wait for or what control to look at. For instance, if I'm changing the amount of colors from 256 to 16 million, the program "thinks" for a few seconds while doing this. I looked at the processes in Task Manager and I didn't see a new one pop up while the program is processing the instructions. Try using winwait("resize") as suggested. Also try changing the option for window title matching. Link to comment Share on other sites More sharing options...
Olson Posted February 8, 2014 Author Share Posted February 8, 2014 Yeah, WinWait("resize") does nothing. Link to comment Share on other sites More sharing options...
somdcomputerguy Posted February 8, 2014 Share Posted February 8, 2014 You may want to refer to this in the Help file - http://www.autoitscript.com/autoit3/docs/functions/AutoItSetOption.htm#WinTitleMatchMode - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
nullschritt Posted February 8, 2014 Share Posted February 8, 2014 You may want to refer to this in the Help file - http://www.autoitscript.com/autoit3/docs/functions/AutoItSetOption.htm#WinTitleMatchMode Try option 2. Link to comment Share on other sites More sharing options...
Werty Posted February 8, 2014 Share Posted February 8, 2014 Why not use PSP's own recording function, in "File/Script/Start recording", I use an old version of PSP also (9) and use the recording function frequently with good results. Some guy's script + some other guy's script = my script! Link to comment Share on other sites More sharing options...
BlackDawn187 Posted February 8, 2014 Share Posted February 8, 2014 It would be helpful if you included more code or, what exactly you're working with. So members could better assist you. Link to comment Share on other sites More sharing options...
Olson Posted February 8, 2014 Author Share Posted February 8, 2014 I have used PSP recording, but I can't seem to figure out how to make the code work for a variety of original photo sizes. The code, as it stands is this: expandcollapse popupHotKeySet("{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 $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 Link to comment Share on other sites More sharing options...
somdcomputerguy Posted February 8, 2014 Share Posted February 8, 2014 So is that window titled exactly 'Resize', or is 'Resize' only part of the window title? Refer to post's 12 & 13 if it's only part. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
BlackDawn187 Posted February 8, 2014 Share Posted February 8, 2014 (edited) I have used PSP recording, but I can't seem to figure out how to make the code work for a variety of original photo sizes. The code, as it stands is this: expandcollapse popupHotKeySet("{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 $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 So, For one, Your script is sending keys to the active window. It would be helpful to everyone if you wrote a check to make sure the Window Exists, Then WinActivate it before sending keys. Also, To ensure focus is not pulled away from it, You can make use of BlockInput. Which requires Admin Privileges. Hope this helps at some level. Also, I took it upon myself to partially tidy up your code and, add what I mentioned above; expandcollapse popupHotKeySet("{F7}", "Size") Call("AdminCheck") While 1 Sleep(100) WEnd Func AdminCheck() ;----------------------------------------------------- ; Request Admin Privileges ;----------------------------------------------------- #RequireAdmin $Admin = IsAdmin() If $Admin = 1 Then Return ElseIf $Admin = 0 Then MsgBox(0, "Error", "This application requires Administrative Privleges to function properly," & @CRLF & "Please restart the application to proceed.") Exit EndIf EndFunc Func Size() If WinExists("Resize" Then WinActivate("Resize") WinWaitActive("Resize") BlockInput(1) Send("!i") Send("e") Send("6") Sleep("3000") Send("+r") Sleep("3000") Send("+s") BlockInput(0) 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 $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 = Number($height + 1) $width = Number($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 Else BlockInput(1) ControlClick("Resize", "", "[CLASS:Button; INSTANCE:14]") Sleep("2000") Send("!a") Send("s") Send("h") Sleep("2000") Send("!a") Send("s") Send("h") BlockInput(0) EndIf ElseIf WinExists("Resize") = "0" Then MsgBox(0, "Error", "Resize Window does not exist", 25) EndIf EndFunc /Edit: Fixed my example /Edit2: Added AdminCheck Function for BlockInput purposes Edited February 8, 2014 by BlackDawn187 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