AutoItRocks Posted October 20, 2008 Share Posted October 20, 2008 Currently, I have a script that counts the seconds the computer is idled, and if the idle time is reset to 0 (by mouse movement or a keyboard press), then it sends a windows l key to lock it. The problem is that once it is locked, it keeps locking itself after I unlock it because I don't have time after the unlock to hit my hotkey to kill the script. So, my logic is all wrong. Is there a way to determine if the computer is not idle rather than determine if the idle is reset to zero? Many thanks. Link to comment Share on other sites More sharing options...
Andreik Posted October 20, 2008 Share Posted October 20, 2008 Currently, I have a script that counts the seconds the computer is idled, and if the idle time is reset to 0 (by mouse movement or a keyboard press), then it sends a windows l key to lock it. The problem is that once it is locked, it keeps locking itself after I unlock it because I don't have time after the unlock to hit my hotkey to kill the script. So, my logic is all wrong. Is there a way to determine if the computer is not idle rather than determine if the idle is reset to zero? Many thanks.I don't understand very well what you want to do but check this. Maybe will help you. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
spudw2k Posted October 20, 2008 Share Posted October 20, 2008 (edited) Yea, there are pretty much only two ways to use Idle. Is idle, or isn't it? Moving the mouse or keyb strokes cause a machine to not be idle. Maybe there's just a loop in your code. Can you post where in your code you are having the prob? edit: correction, three ways is not idle, is idle, how long idle. Edited October 20, 2008 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
AutoItRocks Posted October 20, 2008 Author Share Posted October 20, 2008 Thanks for your help. I guess I was hoping there was a way to say on any mouse movement or keyboard click do something, rather than check to see if it is idle. CODEHotKeySet("{Esc}", "_Terminate") Dim $last_active = 0 Dim $Active_Seconds = 1 Dim $timer = TimerInit() $not_idle = _CheckIdle($last_active, 1) While (1) $not_idle = _CheckIdle($last_active) If $not_idle = 0 Then $timer = TimerInit() ToolTip(Int(TimerDiff($timer) / 1000)) Sleep(200) If Int(TimerDiff($timer) / 1000) >= $Active_Seconds Then _KillIExplore() $timer = TimerInit() $not_idle = _CheckIdle($last_active, 1) EndIf WEnd Func _CheckIdle(ByRef $last_active, $start = 0) $struct = DllStructCreate("uint;dword"); DllStructSetData($struct, 1, DllStructGetSize($struct)); If $start Then DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct)) $last_active = DllStructGetData($struct, 2) Return $last_active Else DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct)) If $last_active <> DllStructGetData($struct, 2) Then Local $save = $last_active $last_active = DllStructGetData($struct, 2) Return $last_active - $save EndIf EndIf EndFunc ;==>_CheckIdle Func _KillIExplore($ietry = 10) Send("#l") EndFunc ;==>_KillIExplore Func _Terminate() Exit EndFunc ;==>_Terminate Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 20, 2008 Share Posted October 20, 2008 Thanks for your help. I guess I was hoping there was a way to say on any mouse movement or keyboard click do something, rather than check to see if it is idle. CODEHotKeySet("{Esc}", "_Terminate") Dim $last_active = 0 Dim $Active_Seconds = 1 Dim $timer = TimerInit() $not_idle = _CheckIdle($last_active, 1) While (1) $not_idle = _CheckIdle($last_active) If $not_idle = 0 Then $timer = TimerInit() ToolTip(Int(TimerDiff($timer) / 1000)) Sleep(200) If Int(TimerDiff($timer) / 1000) >= $Active_Seconds Then _KillIExplore() $timer = TimerInit() $not_idle = _CheckIdle($last_active, 1) EndIf WEnd Func _CheckIdle(ByRef $last_active, $start = 0) $struct = DllStructCreate("uint;dword"); DllStructSetData($struct, 1, DllStructGetSize($struct)); If $start Then DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct)) $last_active = DllStructGetData($struct, 2) Return $last_active Else DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct)) If $last_active <> DllStructGetData($struct, 2) Then Local $save = $last_active $last_active = DllStructGetData($struct, 2) Return $last_active - $save EndIf EndIf EndFunc ;==>_CheckIdle Func _KillIExplore($ietry = 10) Send("#l") EndFunc ;==>_KillIExplore Func _Terminate() Exit EndFunc ;==>_Terminate Too much code for a simple function, since there is already a UDF for this in _Timer_GetIdleTime(): #include <Timers.au3> Global $fLocked = False HotKeySet("{ESC}", "_Quit") While 1 If _Timer_GetIdleTime() < 10000 Then If $fLocked Then Sleep(5000); 5sec to hit ESC if console was locked $fLocked = True Send("#l"); Lock console EndIf Sleep(100) WEnd Func _Quit() Exit EndFunc As soon as anything is done with Kybd/Mouse, it will lock. Upon unlocking, there will be 5sec available to hit ESC. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
AutoItRocks Posted October 20, 2008 Author Share Posted October 20, 2008 Sweet...that works perfectly. Thank you PsaltyDS. One last question. Is there a way I can have this work, with the exception of when one key (F14) is pressed? for example, it would be like the computer locks on any input (mouse or keyboard, with the exception of the F14 key. The whole reason I wanted this was so that I could run a script on my pc (and it won't run when the pc is locked). When I leave my computer, I could run this script, and if anyone messes with my computer, it locks it as a safety precaution. My original script sends the f14 key every 270 seconds that my computer is idle. My script thanks to PsaltyDS is #include <Timers.au3> HotKeySet("{!z}", "_Quit") Sleep(1000); 5sec to hit ESC While 1 If _Timer_GetIdleTime() <= 200 Then Sleep(10) Send("#l"); Lock console _Quit() EndIf Sleep(500) WEnd Func _Quit() Exit EndFunc Thanks again. Link to comment Share on other sites More sharing options...
AutoItRocks Posted October 21, 2008 Author Share Posted October 21, 2008 Okay, here are my two sets of code. One presses the left shift key if the computer has been idle 4.5 minutes. The other is for when you leave your computer, and want to protect your computer by locking it if anything happens other than the left shift key. I use this because I have an automation app that doesn't run properly if the computer is locked. However, I would rather the app not run properly than someone use my computer while am away. So, here is my script to press the shift key CODEHotKeySet("{Esc}", "_Terminate") Dim $last_active = 0 Dim $Inactive_Seconds = 270 Dim $timer = TimerInit() $not_idle = _CheckIdle($last_active, 1) While (1) $not_idle = _CheckIdle($last_active) If $not_idle <> 0 Then $timer = TimerInit() ToolTip(Int(TimerDiff($timer) / 1000)) Sleep(200) If Int(TimerDiff($timer) / 1000) >= $Inactive_Seconds Then _KillIExplore() $timer = TimerInit() $not_idle = _CheckIdle($last_active, 1) EndIf WEnd Func _CheckIdle(ByRef $last_active, $start = 0) $struct = DllStructCreate("uint;dword"); DllStructSetData($struct, 1, DllStructGetSize($struct)); If $start Then DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct)) $last_active = DllStructGetData($struct, 2) Return $last_active Else DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct)) If $last_active <> DllStructGetData($struct, 2) Then Local $save = $last_active $last_active = DllStructGetData($struct, 2) Return $last_active - $save EndIf EndIf EndFunc ;==>_CheckIdle Func _KillIExplore($ietry = 10) Send("{LSHIFT}") EndFunc ;==>_KillIExplore Func _Terminate() Exit EndFunc ;==>_Terminate and here is my script I would run just before I leave my desk. CODE#include <Timers.au3> #include <Misc.au3> HotKeySet("{!z}", "_Quit") $dll = DllOpen("user32.dll") Sleep(5000); 1sec to hit ESC While 1 If _Timer_GetIdleTime() <= 200 Then If _IsPressed("{LSHIFT}") Then Sleep(1000) ;MsgBox(0,"_IsPressed", "shift key Pressed") Else Sleep(100) ;MsgBox(0,"_IsPressed", "Some other input occurred") Send("#l"); Lock console _Quit() EndIf EndIf Sleep(500) WEnd Func _Quit() DllClose($dll) Exit EndFunc Does anyone see any way to improve the script, or any possible issues. I have noticed that if I run two autoit scripts at the same time, it occassionally starts opening the start menu on different key presses (like when shift is pressed) 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