Hi Aaron,
- Don't put OnEvent> lines inside any kind of loop, they only need to execute once and the event is setup... just put them at the top.
- Within your MAINLOOP, you need a Wait> to make sure the loop doesn't hog too much CPU and a test to exit the MAINLOOP when you want to exit the macro.
- Your subroutine STARTEVAL will run when the OnEvent> fires, in your case, when you hold the left mouse button down.
I re-wrote your macro and simplified it as much as I could while still trying to have it do *what I think* it is you were trying to do, see below.
One trick to use when writing a macro is not to start coding right away. Take the time to write out what it is you are trying to do in "pseudo-code" first like this:
//setup an event that will fire when the left mouse button is held down
//wait forever until event fires
//if event has fired 2 times already, exit
//when event fires (left mouse button down) capture the X,Y screen coordinates.
//compare them to some known coordinates and if the click was within the box, display a modal message, if outside, display nothing.
//the first click (if within the box coordinates) will display Msg#1
//the second click (if within the box coordinates) will display Msg#2
//immediately after the second click (whether Msgs were displayed or not) a Finished message will be displayed.
If you take the time to write out the pseudo-code, the code for the macro will practically write itself.
Here's my re-write, I added a Modal messagebox in there showing the X,Y coords of the click just for fun. Give this a try...
Code: Select all
OnEvent>KEY_DOWN,VK1,0,STARTEVAL
Let>i=0
Label>MAINLOOP
If>i=2,END
Wait>0.01
Goto>MAINLOOP
SRT>STARTEVAL
Let>i=i+1
GetCursorPos>X,Y
MDL>you clicked at X: %X% Y: %Y%
Let>TopLeft_X[1]=0
Let>BottomRight_X[1]=1024
Let>TopLeft_Y[1]=0
Let>BottomRight_Y[1]=768
Let>TopLeft_X[2]=0
Let>BottomRight_X[2]=1024
Let>TopLeft_Y[2]=0
Let>BottomRight_Y[2]=768
Let>myMessage[1]=This is Message One
Let>myMessage[2]=This is Message Two
Let>X_TopLeft=TopLeft_X[%i%]
Let>X_BottomRight=BottomRight_X[%i%]
Let>Y_TopLeft=TopLeft_Y[%i%]
Let>Y_BottomRight=BottomRight_Y[%i%]
Let>MessageVar=myMessage[%i%]
If>{(%X%>=%X_TopLeft%) AND (%X%<X_BottomRight>=%Y_TopLeft%) AND (%Y%<Y_BottomRight>%MessageVar%
Endif
END>STARTEVAL
Label>END
MessageModal>Finished
Is this sort of what you were trying to do?
Take care and have a good weekend everyone...