Threap Posted March 30, 2009 Posted March 30, 2009 Hello Forum Users,Long time lurker here, making my first post (weeelll... second post, strictly speaking - I posted this same question in the COM forum thinking COM would offer the solution, but no joy, hence the repost. Apologies if this therefore seems familiar. Refunds will not be given). I searched the forums before posting, so forgive me if this question has already been answered!In one of my scripts, I need to display the Windows Task Manager, set it to the "Performance" tab, and put the window into "borderless" mode (removing the window frame/decorations). The latter is what's giving me most trouble. In theory it can be done by simply double-clicking on the CPU load graph or in other places in the window; in practice, this is very unreliable when done from a script!Here's a simplified version of my code. I've highlighted the bit that gives the problems: ;Display task manager. Wait for a window with its CLASSID to appear, then activate it.ShellExecute("Taskmgr.exe")WinWait("[CLASS:#32770]")WinActivate("[CLASS:#32770]");Now switch to Performance tab... send TabRight messages to the SysTab control until the appropriate text is visibleWhile (Not(WinGetText("[CLASS:#32770]","CPU Usage History"))) ControlCommand ("[CLASS:#32770]", "", "[CLASS:SysTabControl32; INSTANCE:1]", "TabRight")WEnd ; yes, I know this loop might never end if something goes wrong. Not my main problem ; now, set Task Manager to "no window border" modeWhile (WinGetText("[CLASS:#32770]","Handles")) ; this is text that is ONLY visible in "frame" mode - disappears in borderless mode! $winpos = WinGetPos("[CLASS:#32770]") MouseClick ("left",$winpos[0]+20,$winpos[1]+90,2,0) ; the (20,90) co-ords relative to window have been chosen to work under XP & Vista - and do, if I move & clicking the mouse manually! Sleep(100)Wend ; the mouse double-click doesn't always work - so we loop, doing it until successThe above code works (pretty reliably) on XP, but fails frequently on Vista and Windows 7 (yes, I know W7 is pre-release at this point but the Task Manager code seems identical to Vista). The failure mode is that it just sits there in the final While() loop, sending mouseclicks that never work.What am I doing wrong? Can anyone offer suggestions for a more reliable/efficient way of accomplishing this task?Thanks for any help you can offer!
jvanegmond Posted March 30, 2009 Posted March 30, 2009 (edited) Unfortunately I don't have Vista or Windows 7 to test with - at the moment, but I think that "sending mouseclicks that never work." gives a good indication what is going on.I think AutoIt's default setting of double clicking is too fast, and after the 100 sleep the next mouse click is too slow after the previous one to be detected as a double click. Try this and play with the sleep:; now, set Task Manager to "no window border" mode While (WinGetText("[CLASS:#32770]","Handles")) ; this is text that is ONLY visible in "frame" mode - disappears in borderless mode! $winpos = WinGetPos("[CLASS:#32770]") MouseClick ("left",$winpos[0]+20,$winpos[1]+90,1,0) Sleep(30) MouseClick ("left",$winpos[0]+20,$winpos[1]+90,1,0) Sleep(100) Wend ; the mouse double-click doesn't always work - so we loop, doing it until successI don't think it is terribly complicated to recreate that window yourself, either. Reading the CPU usage and making a graph are not very complicated tasks. I hope this helps.Edit: I think I should have also said that changing the value of MouseClickDelay ( option ) can help a lot too. Edited March 30, 2009 by Manadar github.com/jvanegmond
Threap Posted March 31, 2009 Author Posted March 31, 2009 Unfortunately I don't have Vista or Windows 7 to test with - at the moment, but I think that "sending mouseclicks that never work." gives a good indication what is going on. I think AutoIt's default setting of double clicking is too fast, and after the 100 sleep the next mouse click is too slow after the previous one to be detected as a double click. Try this and play with the sleep: ; now, set Task Manager to "no window border" mode While (WinGetText("[CLASS:#32770]","Handles")) ; this is text that is ONLY visible in "frame" mode - disappears in borderless mode! $winpos = WinGetPos("[CLASS:#32770]") MouseClick ("left",$winpos[0]+20,$winpos[1]+90,1,0) Sleep(30) MouseClick ("left",$winpos[0]+20,$winpos[1]+90,1,0) Sleep(100) Wend ; the mouse double-click doesn't always work - so we loop, doing it until success I don't think it is terribly complicated to recreate that window yourself, either. Reading the CPU usage and making a graph are not very complicated tasks. I hope this helps. Edit: I think I should have also said that changing the value of MouseClickDelay ( option ) can help a lot too. Hi, Thanks for the tip - I've tried changing my code to incorporate your suggestion and it seems to work much more reliably now under Vista/W7. And no, recreating the CPU graphs wouldn't be terribly complicated - but why re-invent the wheel?
xXUlTiMaTeSiNXx Posted March 31, 2009 Posted March 31, 2009 It is my understanding that windows dose not alow the automation of taskmanager, however functions performed by the taskmanager can oftern be preformed by AutoIT. I'm new to AutoIT, please help me where you can.[size=10]Profanity is the one language that all programmers understand[/size]
jvanegmond Posted March 31, 2009 Posted March 31, 2009 Hi,Thanks for the tip - I've tried changing my code to incorporate your suggestion and it seems to work much more reliably now under Vista/W7. And no, recreating the CPU graphs wouldn't be terribly complicated - but why re-invent the wheel? Good thinking.Maybe you can also use PixelGetColor to check if a certain color changes to black. Although, that may not be very reliable. github.com/jvanegmond
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