legend Posted March 20 Share Posted March 20 (edited) When I leave my desk, and forget to lock my pc, someone is often writing stuff on my pc... So here's a script that locks it after 5 seconds of inactivity, you can always increase it. expandcollapse popup#include <Misc.au3> Global $iIdleThreshold = 20000 ; 20 seconds in milliseconds While True Local $iLastInputTime = TimerInit() Local $bActivityDetected = False While TimerDiff($iLastInputTime) < $iIdleThreshold For $i = 0x01 To 0xFF If _IsPressed(Hex($i, 2)) Then $bActivityDetected = True ExitLoop EndIf Next ; Get initial mouse position $aInitialMousePos = MouseGetPos() ; Allow a small delay to detect mouse movement Sleep(50) ; Check for mouse movement $aCurrentMousePos = MouseGetPos() If $aInitialMousePos[0] <> $aCurrentMousePos[0] Or $aInitialMousePos[1] <> $aCurrentMousePos[1] Then $bActivityDetected = True ExitLoop EndIf Sleep(100) ; Adjust the sleep time as needed for better responsivenesds WEnd If $bActivityDetected Then ConsoleWrite("Keyboard or mouse activity detected." & @CRLF) Else ConsoleWrite("No keyboard or mouse activity detected." & @CRLF) ShellExecute("rundll32.exe", 'user32.dll,LockWorkStation') EndIf WEnd Edited March 20 by legend Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 20 Moderators Share Posted March 20 Lol, I used to do that to people!!! Turn their screens upside down too 😂 Global $iIdleThreshold = 20000 ; 5 seconds in milliseconds That's 20 seconds btw... Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Nine Posted March 20 Share Posted March 20 _Timer_GetIdleTime does that for you... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
legend Posted March 21 Author Share Posted March 21 9 hours ago, Nine said: _Timer_GetIdleTime does that for you... I didn't knew that function, in that case, the code could be replaced with: #include <Timers.au3> while 1 sleep(5000) $iIdleTime = _Timer_GetIdleTime() if $iIdleTime > 4999 then $iIdleTime = "" ShellExecute("rundll32.exe", 'user32.dll,LockWorkStation') EndIf WEnd 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