Docfxit Posted April 27, 2015 Share Posted April 27, 2015 I have this script with two hotkeys. The F4 hotkey works fine. The F7 hotkey doesn't work.#include <MsgBoxConstants.au3> AutoItSetOption("TrayIconDebug", 1) ;0-off ; Set so that tray displays current line number HotKeySet("{F4}", "ExitProg") HotKeySet("{F7}", "StartStop") $On = True While $On = True Local $iFreeSpace = DriveSpaceFree("E:" & "\") ; Find the free disk space of the home drive, generally this is the C:\ drive. If $iFreeSpace < 1000 Then ;Less than 1gb $megs = $iFreeSpace * .1024 MsgBox($MB_SYSTEMMODAL, "", "Free Space: " & $megs & " MB") Run("C:\Batch\CleanTemp.bat") EndIf Sleep(7200000) ; Two hours WEnd Func StartStop() If $On = False Then $On = True Else $On = False EndIf EndFunc Func ExitProg() Exit EndFuncHow can I fix it so the F7 hotkey works?Thank you,Docfxit Link to comment Share on other sites More sharing options...
Danp2 Posted April 27, 2015 Share Posted April 27, 2015 Perhaps something like this:#include <MsgBoxConstants.au3> AutoItSetOption("TrayIconDebug", 1) ;0-off ; Set so that tray displays current line number HotKeySet("{F4}", "ExitProg") HotKeySet("{F7}", "StartStop") $On = True While True If $On Then Local $iFreeSpace = DriveSpaceFree("E:" & "\") ; Find the free disk space of the home drive, generally this is the C:\ drive. If $iFreeSpace < 1000 Then ;Less than 1gb $megs = $iFreeSpace * .1024 MsgBox($MB_SYSTEMMODAL, "", "Free Space: " & $megs & " MB") Run("C:\Batch\CleanTemp.bat") EndIf EndIf Sleep(7200000) ; Two hours WEnd Func StartStop() $On = Not $On EndFunc Func ExitProg() Exit EndFunc Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
blakel Posted April 27, 2015 Share Posted April 27, 2015 It may be working, but it will take 2 hours to see it. Link to comment Share on other sites More sharing options...
blakel Posted April 27, 2015 Share Posted April 27, 2015 (edited) You are going to have to change your loop to something much smaller, maybe a few hundred milliseconds. (See the help file on HotKeySet)Start a timer when you you run the batch file and then check the timer for a minimum two hour differential at the If $iFreeSpace block.TimerInit/TimerDiff may work or you may have to use macros to get the current time and subtract from last time the batch file was run. Edited April 27, 2015 by blakel Be careful with this as the batch file is likely to take longer to run than you would want to check for user input and put it tnto a strange loop with a lot of disk usage. Link to comment Share on other sites More sharing options...
Docfxit Posted April 27, 2015 Author Share Posted April 27, 2015 That's the problem exactly. My logic is wrong because it takes 2hrs to see it.The F4 works instantly.The F7 may work if I waited 2hrs.Danp2I like your coding. I think it's still waiting .Thanks,Docfxit Link to comment Share on other sites More sharing options...
sdfaheemuddin Posted April 28, 2015 Share Posted April 28, 2015 Try thisinclude <MsgBoxConstants.au3> AutoItSetOption("TrayIconDebug", 1) ;0-off ; Set so that tray displays current line number HotKeySet("{F4}", "ExitProg") HotKeySet("{F7}", "StartStop") $On = True Adlibregister("cleanup",7200000) While True WEnd Func cleanup()If $On Then Local $iFreeSpace = DriveSpaceFree("E:" & "\") ; Find the free disk space of the home drive, generally this is the C:\ drive. If $iFreeSpace < 1000 Then ;Less than 1gb $megs = $iFreeSpace * .1024 MsgBox($MB_SYSTEMMODAL, "", "Free Space: " & $megs & " MB") Run("C:\Batch\CleanTemp.bat") EndIf EndIf EndFunc Func StartStop() $On = Not $On EndFunc Func ExitProg() Exit EndFunc Link to comment Share on other sites More sharing options...
Danp2 Posted April 28, 2015 Share Posted April 28, 2015 You should still put a call to Sleep in your While loop. Otherwise, you are eating too many cpu cycles. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Docfxit Posted April 28, 2015 Author Share Posted April 28, 2015 I added a Sleep in the While loop. I changed the hotkey just in case the F7 was used by something else.I added a tooltip to see if the hot key was recognized.The tooltip stays open all the time. Even when I press Shift-Alt-dThe script exits immediately when I press F4#include <MsgBoxConstants.au3> AutoItSetOption("TrayIconDebug", 1) ;0-off ; Set so that tray displays current line number HotKeySet("{F4}", "ExitProg") HotKeySet("+!d", "StartStop") ; Shift-Alt-d $On = True Adlibregister("cleanup",7200000) While True Sleep(500) ToolTip('Script is "True"', 500, 300) WEnd ToolTip("") Func cleanup() If $On Then Local $iFreeSpace = DriveSpaceFree("E:" & "\") ; Find the free disk space of the home drive, generally this is the C:\ drive. If $iFreeSpace < 1000 Then ;Less than 1gb $megs = $iFreeSpace * .1024 MsgBox($MB_SYSTEMMODAL, "", "Free Space: " & $megs & " MB") Run("C:\Batch\CleanTemp.bat") EndIf EndIf EndFunc Func StartStop() $On = Not $On EndFunc Func ExitProg() Exit EndFuncWhy does the F4 work immediately and the Shift-Alt-d doesn't work at all? Thanks,Docfxit Link to comment Share on other sites More sharing options...
sdfaheemuddin Posted April 28, 2015 Share Posted April 28, 2015 ToolTill inside the loop#include <MsgBoxConstants.au3> AutoItSetOption("TrayIconDebug", 1) ;0-off ; Set so that tray displays current line number HotKeySet("{F4}", "ExitProg") HotKeySet("+!d", "StartStop") ; Shift-Alt-d $On = True Adlibregister("cleanup",7200000) While True Sleep(500) ToolTip('Script is "' & $On & '"', 500, 300) WEnd Func cleanup() If $On Then Local $iFreeSpace = DriveSpaceFree("E:" & "\") ; Find the free disk space of the home drive, generally this is the C:\ drive. If $iFreeSpace < 1000 Then ;Less than 1gb $megs = $iFreeSpace * .1024 MsgBox($MB_SYSTEMMODAL, "", "Free Space: " & $megs & " MB") Run("C:\Batch\CleanTemp.bat") EndIf EndIf EndFunc Func StartStop() $On = Not $On EndFunc Func ExitProg() Exit EndFunc If you want to cleanup as soon as shift+alt+d is pressed then call cleanup() in StartStop function Link to comment Share on other sites More sharing options...
Docfxit Posted April 28, 2015 Author Share Posted April 28, 2015 That works great.Thank you very much, Docfxit 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