Hello All,
I have several questions about AutoHotkey, some of which may prove to be very easy to answer and others which might be impossible (I’m not sure if I can do everything that I want to do with this program).
First off, I wanted to make a script that would wait for any of several conditions, namely, the existence of a certain window, and then do a certain action. My trouble is that I cannot get the script to wait for all possibilities at the same time. If I ask the program to do a command like:
;--------------------------------------
IfWinExist, Sign On
{
IfWinNotActive, Sign On, WinActivate, Sign On
WinWaitActive, Sign On
Sleep, 10
Send, username{TAB}password{ENTER}
return
}
Else, return
;--------------------------------------
What happens is the command executes (i.e. my username and password is automatically entered) the first time the window “Sign On” appears, but after that it just ends up waiting forever. What confuses me is that the following script does work:
;--------------------------------------
loop
{
winwait, Sign On
IfWinNotActive
WinActivate
WinWaitActive
Sleep, 10
Send, username{TAB}password{ENTER}
}
;--------------------------------------
The problem with this looping is that I cannot get a second command to execute and I cant think of a way I could.
Then if I want to make a second command I would write:
;--------------------------------------
IfWinExist, Sign On
{
IfWinNotActive
WinActivate
WinWaitActive
Sleep, 10
Send, username{TAB}password{ENTER}
return
}
Else, gosub, Error
Error:
IfWinExist, There has been an error
{
IfWinNotActive,
WinActivate
WinWaitActive
Sleep, 1000
Send, {ENTER}
return
}
Else, return
;--------------------------------------
(so, the username and password are entered, and if an error happens it automatically acknowledges the error after 1 second)
What happens is that the first time the “Sign On” prompt appears my username and password are entered, but after that nothing happens. Errors are not acknowledged and no more usernames or passwords are entered.
Is there some generic problem with the “IfWinExist” “gosub” and “else” commands? Why do these never work for me?
Chiefly, how can I get a number of triggers to each signal a different reaction, with out waiting for them all to be done consecutively? Say I want to sign on, then acknowledge two errors, then sign on to a different job (they all have the same user/pass). How do I do that?
The bigger job I have is to create a GUI. I am so new to doing this its scary. 2 weeks ago I had no idea any of this was possible for me to learn in my lifetime. I’ve already made a lengthy script that is helping a lot of people do their jobs faster around here. I’ve defined many hotkeys, and I am really liking the hotstrings approach, where I can open any of the common directories in windows by scripting:
::*progs::
Run C:\Program Files\
Return
It makes windows feel wonderfully like Autocad.
Anyway, about the GUI. I need to create a program that works with a user-created, predefined text file to execute a large amount of repetitions of the same action, differing by one variable each time. I don’t know the correct syntax for the script yet, but my intuition tells me to use variables like the following:
(I have read all the docs on the AutoHotkey website, but im not exactly clear on how I should make this happen)
Loop
{
Send, F2 ;this opens a dialogue that asks something to the effect of “where do you want to go?”
Send, %current_pannel%
;this would be a variable created by the database.
;For example, it would start at, “1-A1GRP1” and then go to “1-A2GRP2” and so on
;down the 1-A1 section until it got to 1-B1. However it would not be necessarily
;sequential. It would, for example, start at 1-A16, then 1-A17, then 1-A24,
;then 1-A25 etc. These would be written in a database file, starting with the first
;alphabetically and proceeding to the last, however the order is not important,
;except for organization to the person creating it.
<some sleep function that would wait for any part of that window title to change to, for 1-A%num%GRP1, “num”>
Sleep 250 ;just to wait for a little extra time for it to load
Loop %points per group%
;where %points per group% would come from the amount of points
;to be inserted per group
{
<move mouse to %mx%,%my%> ; where the %mx% and %my% are the mouse x-cordinates and the mouse y-cordinates of the first point to be inserted
Send, {INS}%point%{ENTER}
WinWait, Edit Point Entry
Send, {ENTER}
;where %point% is the first point to create on that page. It would look something
;like “VAR17”, which would, after {ENTER} was pressed, convert automatically
;to “1-A16VAR17”. That conversion is already done by the program I am
;making the script for.
}
;----------------------------------------------------------------------
;the second iteration of the above loop would look like this
; <move mouse to %mx%,%my%>
; this would be different predefined coordinates of different a
;different predefined point
;Send, {INS}%point%{ENTER}{ENTER}
; this would be different %point% than the first one. For example “VAR18”
;----------------------------------------------------------------------
Send, {ESC}
WinWait, Save Changes?
Send, {ENTER}
}
Other things that this program would have to include is that for all “VAR18”s entered, a sequence would have to be entered that would change the point to a different type of point. For example a yellow text one. The script for this is:
;---------------------------------------------------------------
;“change to yellow”
WinWait, Edit Reliable Point,
IfWinNotActive, Edit Reliable Point, , WinActivate, Edit Reliable Point,
WinWaitActive, Edit Reliable Point,
MouseClick, left, 208, 164
Sleep, 10
WinWait, Select Color,
IfWinNotActive, Select Color, , WinActivate, Select Color,
WinWaitActive, Select Color,
MouseClick, left, 206, 86
Sleep, 10
MouseClick, left, 93, 276
Sleep, 10
WinWait, Edit Reliable Point,
IfWinNotActive, Edit Reliable Point, , WinActivate, Edit Reliable Point,
WinWaitActive, Edit Reliable Point,
MouseClick, left, 183, 188
Sleep, 10
WinWait, Select Color,
IfWinNotActive, Select Color, , WinActivate, Select Color,
WinWaitActive, Select Color,
MouseClick, left, 208, 94
Sleep, 10
MouseClick, left, 76, 270
Sleep, 10
WinWait, Edit Reliable Point,
IfWinNotActive, Edit Reliable Point, , WinActivate, Edit Reliable Point,
WinWaitActive, Edit Reliable Point,
MouseClick, left, 178, 214
Sleep, 10
WinWait, Select Color,
IfWinNotActive, Select Color, , WinActivate, Select Color,
WinWaitActive, Select Color,
MouseClick, left, 210, 97
Sleep, 10
MouseClick, left, 85, 271
Sleep, 10
WinWait, Edit Reliable Point,
IfWinNotActive, Edit Reliable Point, , WinActivate, Edit Reliable Point,
WinWaitActive, Edit Reliable Point,
MouseClick, left, 71, 376
Sleep, 10
;---------------------------------------------------------------
Also, all “TL%num%”, “PRG%num%” and “GRP%grpnum%” points would have to be invisible and sized to a specific size.
For example,
; ---------------------------------------------------------------
<move mouse to %mx%,%my%>
;where the top left corner of that TL invisible link is supposed to be
Send, {INS}%point%{ENTER}{ENTER}
;this would be like, “TL1”
<move mouse to %mx-1%,%my-1%>
;this would move the mouse to one below and one across from
;where the original top left corner of the point was palced
Send, s
;this allows sizing of the point
Send, {SHIFTDOWN}
;this allows the point to be sized in X and Y coordinates independently
; i.e. not in proportion to eachother
<move mouse to %mx2%,%my2%>
;this would be the lower right hand corner of where the TL invisible
;link would cover
Send, mouseclick, left
;locks the lower right corner
Send, {SHIFTUP}
;the program would then move to the next point to be inserted
; ---------------------------------------------------------------
I would like the resulting GUI to have an interface that allows the creation of the %mx%,%my% for all the points on a given graphic. Im not sure how to get this data to append it self to the end of a text file in an orderly fassion, and then store that data as a variable that changes with each iteration of the loop.
The interface would have a look similar to:
http://img86.imageshack.us/my.php?image ... ionor3.png
Where links with values would have any size that would allow the link number to fit, and links that were invisible would be the size of the desired invisible link. In that graphic, 42, 44, 46, 48, and 50 are menu links which are invisible, 28, 32, and 30 are program links (also invisible), and 36, 34 are other invisible links. Number 0 is an exception to the GRP rule (where “GRP” links have to be invisible) This link should be a larger text size than the other text points. This data can be entered after in the place of %text size% the command {Send, {INS}1a1grp1{ENTER}%text size%}. Where %text size% would include a command string similar to the “change to yellow” command (they use the same control box when inserted).
Perhaps it would be better just to have the links created each individually rather than a rule and exceptions? This would not be too much work, as the resulting script (that would run all the iterations) would be saving several days of work and doing it all in under an hour.
Anyway, I can get into more specifics later. Im just looking for some initial feedback on this now. Anyone have some basic structure I should follow? Comments?
Thanks
fogus