IanN1990 Posted December 8, 2011 Share Posted December 8, 2011 (edited) Heya, So basicly, when i click the desktop it shows it, when i "unclick it" it runs the time.exe which is a empty shell of code that lasts for 5 seconds and then hides the desktop. Is there any other way of going about this would wouldn't slow down the code. "if i put a sleep(5000) then the whole code is slowed down by 5 seconds whereas this way it will keep check every 500 mii seconds" while 1 sleep(500) if winactive("[Class:Progman]") Then $hide=0 ControlShow("Program Manager", "", "[CLASS:SysListView32; INSTANCE:1]") Else if $hide=0 then run("D\time.exe") if proccessexist("time.exe") then else $hide=1 ControlHide("Program Manager", "", "[CLASS:SysListView32; INSTANCE:1]") EndIf EndIf wend Edited April 14, 2012 by IanN1990 Link to comment Share on other sites More sharing options...
water Posted December 8, 2011 Share Posted December 8, 2011 Put the above code in a function and call it every xxx milliseconds using AdlibRegister(function, xxx) My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
IanN1990 Posted December 8, 2011 Author Share Posted December 8, 2011 doesn't that mean it runs both scripts at the same time *main script and this function script" , doubling the cpu ? When i only want it to run a timer if when a condition ends ? Link to comment Share on other sites More sharing options...
Blue_Drache Posted December 8, 2011 Share Posted December 8, 2011 While 1 Sleep(10) $temp = TimerInit() if TimerDiff($temp) > 500 Then _DoSomething() $temp = TimerInit() EndIf WEnd Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
water Posted December 8, 2011 Share Posted December 8, 2011 AutoIt can't do two things at the same time. With AdlibRegister is stops execution of the main code every xxx milliseconds, calls the specified function and then returns to the main code. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
IanN1990 Posted December 8, 2011 Author Share Posted December 8, 2011 (edited) Hmm a intereseting function but that means every 250 sec my script loses focus for the check "as my script also runs lots of mousepos checks to show applications and taskbars but thanks for the post @Blue i ran ur code, and it didn't really seam to do anything :S but the idea was soild and helped me with an answer if winactive("[Class:Progman]") Then $hide=0 $loop = 0 ControlShow("Program Manager", "", "[CLASS:SysListView32; INSTANCE:1]") Else if $hide=0 then $loop = $loop + $num if $loop = 5 Then $hide=1 ControlHide("Program Manager", "", "[CLASS:SysListView32; INSTANCE:1]") EndIf EndIf EndIf Every main loop, it adds 1. So 10 loops = 500 per loop = 5 sec delay works nicely Alot more so then running a extra exe ^^ Edited December 8, 2011 by IanN1990 Link to comment Share on other sites More sharing options...
Blue_Drache Posted December 8, 2011 Share Posted December 8, 2011 My code was example code showing you how to use the timerinit and timerdiff functions. Look them up in the help file. _DoSomething is a bogus function that does NOTHING because ... well ... the function calling it doesn't exist. I'm not here to spoonfeed you code. Engage your brain and you'll figure it out.... My code will call the undefined function every 500ms or so ... you just have to write what it's bouncing out to go do. Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
BrewManNH Posted December 8, 2011 Share Posted December 8, 2011 If you change Blue_Drache's code to the code below it will show you how to delay it correctly, his code resets the timer every time through the loop. $temp = TimerInit() ; this has to be outside the while loop While 1 if TimerDiff($temp) > 500 Then ConsoleWrite("Timer reset again" & @LF) $temp = TimerInit() ; Resets the timer Else sleep(10); so the script doesn't overload the CPU EndIf WEnd This will display a ConsoleWrite in SciTE if you run it from there. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
IanN1990 Posted December 9, 2011 Author Share Posted December 9, 2011 (edited) I didn't mean it like that Blue I did add the function and name, and when that failed i replaced the function with a msgbox "as i use msgboxes for finding out where code is breaking" and nothing really happened. Thats what i ment Your code with _DoSomething() replaced with a Msgbox. Running the code after 500 Mili seconds should make the msgbox appear but nothing happens While 1 Sleep(10) $temp = TimerInit() if TimerDiff($temp) > 500 Then MsgBox(4096, "Test", "This box will time out in 10 seconds", 10) $temp = TimerInit() EndIf WEnd Looking at BrewManNH post it does seam like the first TimerInIt() was in the wrong location, preventing the code from working correctly but its still nice to have a more professional timer coding then my old exe or loop ideas Edited December 9, 2011 by IanN1990 Link to comment Share on other sites More sharing options...
Blue_Drache Posted December 9, 2011 Share Posted December 9, 2011 (edited) Oops, I was **SURE** I had that init outside the loop. My bad. Sorry for jumping to grouchy conclusions. Edited December 9, 2011 by Blue_Drache Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
IanN1990 Posted December 9, 2011 Author Share Posted December 9, 2011 no harm done 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