OldManJack Posted September 17, 2007 Share Posted September 17, 2007 (edited) I'm trying to get a macro that will periodically (every tenth of a second) export the mouse position and time elapsed to a non-active notepad window. Until I can get everything else working, I've been manually opening a notepad window and entering the controlsend() parameters. I've got it to the point where there aren't any error messages, but nor is there any data visible in the notepad document. I'd especially appreciate more information on: the first While-WEnd loop I'm using to run the controlsend() and exactly why its completely misused and very silly looking, how to activate the timer/counter on a mouseclick, and how to include a line-return in a send() "text." Thankyou in advancedGlobal $PausedHotKeySet("{PAUSE}", "TogglePause")HotKeySet("{ESC}", "Terminate")Opt("MouseCoordMode", 0) ;1=absolute, 0=relative, 2=cellWhile 1 ;the expression is a non-zero number, creating an infinite loop$pos = MouseGetPos() Controlsend( "Untitled-Notepad", "", "[Class: Edit: Instance:1]" , "x,y,t:" & $pos[0] & "," & $pos[1]) ; add tick counter, line return Sleep(100)WEndFunc TogglePause() $Paused = NOT $Paused While $Paused sleep(100) ToolTip('Script is "Paused"',0,0) WEnd ToolTip("")EndFuncFunc Terminate() Exit 0EndFunc Edited September 17, 2007 by OldManJack Link to comment Share on other sites More sharing options...
tAKTelapis Posted September 17, 2007 Share Posted September 17, 2007 Hope this helps (Script that outputs co-ords for mouse ever 30 milliseconds to C:\test.txt , You can easily add in your pause function etc) And its all nicely commented. Opt("OnExitFunc", "endscript") ; So that the file gest closed on exit AdLibEnable("_GetPos", 30) ; Run the _GetPos() function ever 30 ms $file = "c:\test.txt" ; Specify the text file for writing co-ords to $file = FileOpen($file, 9) ; Open it, and test to see that it exists If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 Sleep(10) ; Hang around to keep things running WEnd Func _GetPos() ; Function to get the mouses position, and write it to the text file $pos = MouseGetPos() FileWriteLine($file, $pos[0] & "-" & $pos[1]) EndFunc ;==> _GetPos() Func endscript() ; function to run when autoit exists FileClose($file) ; Closes the file handle on exit EndFunc HTH /tAK Link to comment Share on other sites More sharing options...
OldManJack Posted September 17, 2007 Author Share Posted September 17, 2007 (edited) #Edit: Taktelapis, you are a wonderfull human being---I've dropped the controlsend() for now and I've got it down to the following, which works in its entirety. Which means my problem was with the controlsend(). Help is still needed.Global $PausedHotKeySet("{PAUSE}", "TogglePause")HotKeySet("{ESC}", "Terminate")Opt("MouseCoordMode", 0) ;1=absolute to screen, 0=relative to window, 2=cellRun("Notepad.exe")winwaitactive("Untitled - Notepad")While 1 ;the expression is a non-zero number, creating an infinite loop $pos = MouseGetPos() Send("x,y,t: " & $pos[0] & "," & $pos[1] & "{Enter}") ; add tick counter Sleep(100)WEndFunc TogglePause() $Paused = NOT $Paused While $Paused sleep(100) ToolTip('Script is "Paused"',0,0) WEnd ToolTip("")EndFuncFunc Terminate() Exit 0EndFunc Edited September 17, 2007 by OldManJack Link to comment Share on other sites More sharing options...
tAKTelapis Posted September 17, 2007 Share Posted September 17, 2007 Well, not sure about anything like an _IsClicked() function, so no idea towards getting it running when someone clicks. But as for the line return, if you go with it being output directly to the text file, it takes care of it for you. Otherwise: For $i = 1 to 10 WinWaitACtive("Untitled - Notepad") Send("a" & @CR) Next @CR <- Inbuilt macro or whatever they call it, which is the equiviant to hitting "enter" @CRLF <- Same sort of thing, except it out puts a double "enter", so it leaves a blank line between each line. As for the While loop.. Don't see anything "unko" with it as it were, Its a pretty standard loop, Though you might find it easier to read things if you Tab them. Link to comment Share on other sites More sharing options...
OldManJack Posted September 17, 2007 Author Share Posted September 17, 2007 Ok. Let me run through the commands and functions to make sure I understand their purpose. Opt("OnExitFunc", "endscript"); So that the file gest closed on exit Opt("OnExitFunc" , "endscript") Is a autosetoption that performs a function as the program in closing, in this case, one that closes a file by the name of $file, previosuly defined as C:\test.text. AdLibEnable("_GetPos", 30); Run the _GetPos() function ever 30 ms I'm a little fuzzy on the AdLibEnable() function. I'm guessing it works a bit like a self contained 'always do this' statement, yes? It executes the function _getPos eveyr 30 ms. (The "_" is a personal method of organizing Functionnames or a mostly universal thing that I'll see often enough that I should know it? I also noticed that most of the forum chatter talking about AdLibEnable() and AdLibDisable() are doing so in relationship to error messages, which I don't quite underdtand yet either. Why would you need a script running continiously to check for errors and call a msgbox? People are also using phrases like "saving the CPU," which sounds like something I should know about. $file = "c:\test.txt"; Specify the text file for writing co-ords to $file = FileOpen($file, 9); Open it, and test to see that it exists If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf The next few lines assign the variable $file to c:\test.txt, tests its existance, and if it doesn't exist, then creates an error message and exits the script (The 'Exit' function, right?) What I don't know about is the "-1" part of "If $file = -1 Then" I'd halfway expect to see a "0" (zero) for negative return. Why -1 specifically? Or possibly an easier question for you to answer, what should I have read? While 1 Sleep(10); Hang around to keep things running WEnd Without the While-WEnd loop, the script would pause or exit? Func _GetPos(); Function to get the mouses position, and write it to the text file $pos = MouseGetPos() FileWriteLine($file, $pos[0] & "-" & $pos[1]) EndFunc;==> _GetPos() Begins the _GetPos() function, assigns the $pos variable to MouseGetPos(), then uses the FileWriteLine command to write into $file, previously defined as c:\test.txt in the format of ###-###. The same function still run if you used $cheese = MouseGetPos() and FileWriteLine($Cheese[0] & "-" & $Cheese[1]) ? Hopefully, this will set me straight to finish the thing up. Thanks much. 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