 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
senseijustint Guest
|
Posted: Sun Dec 27, 2009 10:36 pm Post subject: Pausing/unpausing script from another script |
|
|
Really new to AHK so bear with me cuz probably doing things the hard way!
Writing script that opens a webpage, then a mainframe emulator, sends info and closes.
Part of it is saving info to an .ini file if it does not exist.
Wrote a separate script for this since need several GUI's and get errors due to needing buttons w/same names to do different things.
Anyway problem i'm running into is I pause the original script when it runs the other one and then use:
Detecthiddenwindows, on
settitlematchmode, 2
PostMessage, 0x111, 65306,,, filename
to unpause but this seems to only work once in awhile and randomly.
1/2 time works great....other 1/2 orig script stays paused!
Any suggestions appreciated! |
|
| Back to top |
|
 |
Sergio
Joined: 16 Mar 2008 Posts: 160 Location: Brooklyn
|
Posted: Mon Dec 28, 2009 4:31 am Post subject: Re: Pausing/unpausing script from another script |
|
|
It's pretty hard to understand what you're saying based on the description. So far I understand that you have several AHK files working separately but calling one anther. Is that right?
I also see that you pause one (from the other?) but then it doesn't always come back from pause.
You can easily reassign different names to the GUI variables and map other hotkeys to avoid the errors/conflicts. Can you put up the code? It's just easier to look at it sometimes.
P.S. Are you a Sensei? _________________
 |
|
| Back to top |
|
 |
senseijustint Guest
|
Posted: Thu Dec 31, 2009 2:04 am Post subject: Pausing/unpausing scripts |
|
|
Nervous about posting code since i don't wanna be responsible for folks laughing themselves to death @ my ineptitude but here goes!
And yes Sergio...i am a sensei.
Main Code:
SetTitleMatchMode 2
setwindelay, 1500
fileread, exists, C:\temp\bnsfinfo.ini
if errorlevel ;if file doesn't exist
{
; call script to create .ini files for info
run "C:\users\justin\desktop\unpwsetup.ahk"
pause
gosub, finishsub
}
else
{
gosub, pwsub
return
}
finishsub:
Run "C:\Program Files\Internet Explorer\iexplore.exe" https://www.bnsf.com/bnsf.was6/emu/main
Mousemove, 0,0
Sleep, 3000
iniread, UN, C:\temp\bnsfinfo.ini, section1, username
iniread, PW, C:\temp\bnsfinfo.ini, section2, password
winwait, Mainframe Login
winactivate, Mainframe Login
statusbarwait, Done, 45
if errorlevel
{
msgbox, The page did not load or was closed!
exitapp
}
else
send %UN%{tab}%PW%{enter}
winwait, Security Warning
send {enter}
winwait, Security Warning
send {enter}
Winwait, WebConnect
winactivate, WebConnect
winmove, WebConnect,,440,300
click 200,300
send bnsf
setkeydelay, 500
send {enter}
setkeydelay, 10
send %UN%{tab}%PW%
setkeydelay, 500
send {enter}
setkeydelay, 10
send nattey{space}
setkeydelay, 500
send {enter}{enter}{enter}
iniread, HTC, C:\temp\bnsfinfo.ini, section3, HomeCity
iniread, HTS, C:\temp\bnsfinfo.ini, section4, HomeState
iniread, POC, C:\temp\bnsfinfo.ini, section5, OfficeCode
StringLen, citylen, HTC
StringLen, statelen, HTS
StringLen, codeLen, POS
If CityLen<2
{
msgbox, city too short
Exitapp
}
Else If StateLen<2
{
msgbox, state too short
ExitApp
}
Else
send 8{enter}14{enter}
setkeydelay, 10
send %HTC%{space}%HTS%
If codelen<2
Send 01{enter}{F12}
Else
Send %POC%{enter}{F12}
ExitApp
pwsub:
MsgBox, 4387,P/W Option,Change Your Password?
IfMsgBox, No
Gosub, finishsub
else IfMsgBox, Cancel
exitapp
else IfMsgBox, Yes
{
iniread, pwtemp, C:\temp\bnsfinfo.ini, section2, password
Gui, +alwaysontop +owndialogs
Gui, Font, s10, arial
Gui, Add, Text, Enter your new 8 digit BNSF password.
Gui, Font, s8, arial
Gui, add, text, (This DOES NOT affect your password for BNSF!)
Gui, add, edit, +limit8 +number vbnsfpw
gui, add, button, default section, OK
Gui, show, w300h200 -sysmenu, New Password
Return
}
ButtonOK:
Gui, Submit
StringLen, length, bnsfpw
ifequal, length, 8
{
iniwrite, %bnsfpw%, C:\temp\bnsfinfo.ini, section2, password
goto, finishsub
}
else
goto, finishsub
unpwsetup code:
gui, +alwaysontop +owndialogs
Gui, font, s10, arial
Gui, Add, Text, w350, Enter your login information to setup AutoLogin
Gui, Add, Text,section, UserName(b number):
Gui, Add, Text,, Password:
Gui, Add, Edit, vbnsfun +limit8 ys ; The ym option starts a new column of controls.
Gui, Add, Edit, vbnsfpw +limit8 +number +password*
Gui, Add, Button, default section, OK
gui, add, button,ys, Cancel
Gui, Show,w400h200, AutoLogin Setup
return ; End of auto-execute section. The script is idle until the user does something.
GuiClose:
ButtonCancel:
DetectHiddenWindows On
SetTitleMatchMode 2
WinClose, emulator3.ahk
ExitApp
ButtonOK:
Gui, Submit ; Save the input from the user to each control's associated variable.
iniwrite, %bnsfun%, C:\temp\bnsfinfo.ini, section1, username
iniwrite, %bnsfpw%, C:\temp\bnsfinfo.ini, section2, password
run "C:\users\justin\desktop\bnhtsetup.ahk"
exitapp
return
bnhtsetup code:
;this code sets up special info
{
Gui, +Alwaysontop +owndialogs
Gui, font, s10, arial
Gui, Add, Text, W350, Enter Home Terminal Information.
Gui, font, s8, arial
Gui, Add, text, w350, (If You don't know, Click Cancel! You can add this later)
Gui, Font, s10, arial
Gui, Add, text, section, Program 333 city:
Gui, add, text,, State(ex. AZ):
Gui, add, text,, Program Office Code(ex. 01):
gui, add, edit, vHomeCity +limit9 +uppercase ys
gui, add, edit, vHomeSt +limit2 +uppercase
Gui, add, edit, vOffcode +limit2 +number
Gui, add, Button, default section, OK
Gui, add, Button, ys, Cancel
Gui, Show, w400h300 -sysmenu, Autologin Setup
Return
guiClose:
guiescape:
ButtonCancel:
ButtonOK:
Gui, Submit
iniwrite, %HomeCity%, C:\temp\bnsfinfo.ini, section3, HomeCity
iniwrite, %HomeSt%, C:\temp\bnsfinfo.ini, section4, HomeState
iniwrite, %OffCode%, C:\temp\bnsfinfo.ini, section5, OfficeCode
Detecthiddenwindows, on
settitlematchmode, 2
PostMessage, 0x111, 65306,,, emulator3.ahk
exitapp
}
Prolly easier ways to do this but this is what i got! Also for diagnostic purposes it'll be hard cuz can't actually be done w/o proper login information! Any help tho i appreciate!
So when i tried to put it all in one script w/gui's in separate subroutines i get the 'duplicate labels' error. All i could find was ways to change name of gui so can be called by another one. |
|
| Back to top |
|
 |
Sergio
Joined: 16 Mar 2008 Posts: 160 Location: Brooklyn
|
Posted: Thu Dec 31, 2009 5:31 am Post subject: |
|
|
Well, it's not as bad as you made it out to seem. There are ways to write it so that it would be more efficient, but unless you've written for a long time, it will not come naturally. Writing efficiently is significantly more important when you're collaborating with others or when you plan on expanding on or reusing that code. You're right though. Without the login information or the other hotkey, it does make troubleshooting very difficult. There are a few things which I can help with though.
If you can avoid it, you really don't want to have one hotkey call another. You already seem to know how to work with subroutines and the next logical progression is to work with functions. It may seem like the easy solution to call an external AHK, but the problem is that it opens your code up to a new world of problems! You are now dependent on external factors that are not self contained within AuotHotkey.
I imagine that the initial motivation to do this was to have a second function working asynchronously. This can also be done within the same hotkey. Not only that: I am sure that in the time that it would take you to troubleshoot this one script and get it to work, you could just as easily learn the right way to do this to avoid the pitfall altogether in the future. This is a very good place to start.
Secondly, I can tell you that there isn't anything that you can do about the titles of Subroutines. By definition they must be different. I like to group them into different categories to make it easier. IE ButtonOK_First & ButtonOK_Second. ButtonClose_First &ButtonClose_Second, etc.
Finally, I can tell you that the code which is useless also seems nonintrusive. IE Mousemove, 0,0 may not help with anything, but it doesn't hurt either.
Good luck!  _________________
 |
|
| Back to top |
|
 |
senseijustint Guest
|
Posted: Thu Dec 31, 2009 4:25 pm Post subject: |
|
|
Thank u so much for all the help.
I think i understand most of what you are saying. Just to make sure tho..
to have the gui ok button show "OK" on the button but call OK_second would i just add GOk_second in the parameters?
Also the mousemove 0,0 command was from an example to move the mouse away from any controls in on the web window while waiting for the status bar to read done. Is this not necessary?
I am hopiing to be able to distribute this program to co-workers at some point which is why i don't just put my info in!
So again thanks for your time and advice! |
|
| Back to top |
|
 |
Sergio
Joined: 16 Mar 2008 Posts: 160 Location: Brooklyn
|
Posted: Thu Dec 31, 2009 5:35 pm Post subject: |
|
|
I rarely deal with GUIs and I don't think I've ever made an AHK with more than one simultaneous GUI, so I may have lead you astray. I now see that the caption (visible to the viewer) affects the label. That advice was good for subroutines, but not good for buttons.
| Code: |
This GUI command:
Gui, add, Button, default section, OK
Relates to this subsequent routine:
ButtonOK: |
So you have two options. You can either (A) change the name of the button.
| Code: |
This GUI command:
Gui, add, Button, default section, Go
Relates to this subsequent routine:
ButtonGo: |
Or (B) use the Gui Destroy function if the two GUIs do not run simultaneously.
| senseijustint wrote: | | Also the mousemove 0,0 command was from an example to move the mouse away from any controls in on the web window while waiting for the status bar to read done. Is this not necessary? |
It seems that I missed the point on this one. Again due to lack of practice. But if you are reading the status bar it is important to have it there. _________________
 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|