gordo Posted June 30, 2005 Share Posted June 30, 2005 I'm wondering if there's a way to have AutoIT constantly listen in the background for certain triggers like key combinations or window pop-ups, and automatically perform certain scripted actions and then go back to a listening state for the next trigger... until the process is killed. Is there a way to make such a listener as some sort of uber-script with all actions included as subroutines or is there another external facility that provides for this capability? Link to comment Share on other sites More sharing options...
GaryFrost Posted June 30, 2005 Share Posted June 30, 2005 AdlibEnable SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
jpm Posted June 30, 2005 Share Posted June 30, 2005 I'm wondering if there's a way to have AutoIT constantly listen in the background for certain triggers like key combinations or window pop-ups, and automatically perform certain scripted actions and then go back to a listening state for the next trigger... until the process is killed.Is there a way to make such a listener as some sort of uber-script with all actions included as subroutines or is there another external facility that provides for this capability?<{POST_SNAPBACK}>You have to use WinWaitActive in a loop and HotKeySet. Even you can use AdLibEnable to poll Link to comment Share on other sites More sharing options...
gordo Posted June 30, 2005 Author Share Posted June 30, 2005 Thanks, I'll give it a shot. Link to comment Share on other sites More sharing options...
gordo Posted July 1, 2005 Author Share Posted July 1, 2005 Ok, so here's a test script I created that seems to do the trick, although I'm not exactly sure whether this is an efficient way to accomplish my task. I assume that with this structure, I can just keep adding functions and the main program will loop through each one. Is this the right way to go about this? Will this scale to let's say 100 functions without killing the CPU even if I speed up the sleep periods? While 1 AdlibEnable ("notepad_hello", 1000) Sleep (1000) AdlibEnable ("wordpad_goodbye", 1000) Sleep (1000) WEnd Exit Func notepad_hello() If WinActive("Untitled - Notepad") Then ControlClick("Untitled - Notepad", "", 15) Send("hello") Sleep(2000) WinKill("Untitled - Notepad") EndIf EndFunc Func wordpad_goodbye() If WinActive("Document - WordPad") Then ControlClick("Document - WordPad", "", 59648) Send("goodbye") Sleep(2000) WinKill("Document - WordPad") EndIf EndFunc Link to comment Share on other sites More sharing options...
Valuater Posted July 1, 2005 Share Posted July 1, 2005 (edited) I would approach this way (not saying its correct, but it works for me) ;set a hot key to exit While 1 If WinActive("Untitled - Notepad") Then ControlClick("Untitled - Notepad", "", 15) Send("hello") Sleep(2000) WinKill("Untitled - Notepad") EndIf If WinActive("Document - WordPad") Then ControlClick("Document - WordPad", "", 59648) Send("goodbye") Sleep(2000) WinKill("Document - WordPad") EndIf Sleep(100) WEnd just a thought 8) Edited July 1, 2005 by Valuater Link to comment Share on other sites More sharing options...
GaryFrost Posted July 1, 2005 Share Posted July 1, 2005 (edited) Read the help on AdlibEnable, you only need one function, have that function contain all your if statements #NoTrayIcon Opt("TrayOnEventMode",1) Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown. $exit = TrayCreateItem("Exit") TraySetItemOnEvent(-1,"ExitEvent") TraySetState() AdlibEnable("_MyAdlib") While 1 Sleep(10) WEnd Func _MyAdlib() If WinActive("Untitled - Notepad") Then ControlClick("Untitled - Notepad", "", 15) Send("hello") Sleep(2000) WinKill("Untitled - Notepad") EndIf If WinActive("Document - WordPad") Then ControlClick("Document - WordPad", "", 59648) Send("goodbye") Sleep(2000) WinKill("Document - WordPad") EndIf EndFunc Func ExitEvent() Exit EndFunc Edit: added TrayMenu Edit: this is for the Release version of AutoIt, for the Beta change the TraySetItemOnEvent(-1,"ExitEvent") to TrayItemSetOnEvent(-1,"ExitEvent") Edited July 1, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Valuater Posted July 1, 2005 Share Posted July 1, 2005 (edited) Read the help on AdlibEnable, you only need one function, have that functioncontain all your if statements;set a hot key to exit HotKeySet("{ESC}", "Terminate") AdlibEnable("_MyAdlib") While 1 Sleep(100) WEnd Func _MyAdlib() If WinActive("Untitled - Notepad") Then ControlClick("Untitled - Notepad", "", 15) Send("hello") Sleep(2000) WinKill("Untitled - Notepad") EndIf If WinActive("Document - WordPad") Then ControlClick("Document - WordPad", "", 59648) Send("goodbye") Sleep(2000) WinKill("Document - WordPad") EndIf EndFunc Func Terminate() Exit 0 EndFuncEdit: added hot key exit<{POST_SNAPBACK}>doesn't the adlib need to be inside the loop?8) Edited July 1, 2005 by Valuater Link to comment Share on other sites More sharing options...
GaryFrost Posted July 1, 2005 Share Posted July 1, 2005 From the help file, I've used AdlibEnable many times, it runs on it's own loopEnables Adlib functionality.AdlibEnable ( "function" [, time]) Parametersfunction The name of the adlib function to call. time [optional] how often in milliseconds to call the function. Default is 250 ms. Return ValueNone. RemarksEvery 250 ms (or time ms) the specified "function" is called--typically to check for unforeseen errors. For example, you could use adlib in a script which causes an error window to pop up unpredictably.The adlib function should be kept simple as it is executed often and during this time the main script is paused. Also, the time parameter should be used carefully to avoid CPU load.AdlibEnable("myadlib");...ExitFunc myadlib() If WinActive("Error") Then ;... EndIfEndFunc SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
gordo Posted July 1, 2005 Author Share Posted July 1, 2005 (edited) AdLibEnable is such a strange function. It does run in its own internal loop and will max out CPU unless the next command is a sleep(x). But when exactly is the sleep function evaluated? I just don't get it. It doesn't seem to matter what length of time you sleep for either, as the sleep function is not fully evaluated... Can anyone explain what exactly is going on here? Oh, also, each of these lines error out on my computer. How come and what do they do? Opt("TrayOnEventMode",1) Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown. $exit = TrayCreateItem("Exit") TrayItemSetOnEvent(-1,"ExitEvent") TraySetState() Edited July 1, 2005 by gordo Link to comment Share on other sites More sharing options...
Valuater Posted July 1, 2005 Share Posted July 1, 2005 Oh, also, each of these lines error out on my computer. How come and what do they do?Opt("TrayOnEventMode",1)Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown.$exit = TrayCreateItem("Exit")TrayItemSetOnEvent(-1,"ExitEvent")TraySetState()<{POST_SNAPBACK}>I dont care much for adlib, thus i showed you how I would approach the scriptyou are recieving these errors because these function are designed for the BETA Autoit releaseyou can down load it AutoitForums>Autoit v3>Developers>Autoit 3.1.1+++8) 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