weirddave Posted August 28, 2021 Share Posted August 28, 2021 I want to detect when a PC is effectively idle so that I can turn off a wifi controlled socket (Audio Amp). Control of the socket isn't a problem. Detecting Idle is a bit tricky, if I'm watching a video then potentially I won't move the mouse or type. I did look into potentially reading the status of VLC, which is the only media player I use. Unfortunately this is also tricky as I may have multiple instances (max 1 playing while others paused), but in conjunction with other idle detection methods this would give me the greatest flexibility to conjure up a good control strategy for the wifi socket. The viable option I have come up with is to detect that the monitor is off (or has been told to turn off, I believe there may be a difference), but it doesn't seem to be easy. I can get around the monitor switching off while playing audio by using time as a factor, I wouldn't be doing that at night, for example. If anyone has some ideas I'd appreciate it :) Link to comment Share on other sites More sharing options...
markyrocks Posted August 29, 2021 Share Posted August 29, 2021 I'm thinking to determine if screensaver is set to enabled and then check to see if its running. This should probably get you started. via https://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_SystemParametersInfo.htm SPI_GETSCREENSAVEACTIVE 0x0010 SPI_GETSCREENSAVERRUNNING 0x0072 https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfoa?redirectedfrom=MSDN&f1url=%3FappId%3DDev10IDEF1%26l%3DEN-US%26k%3Dk(SystemParametersInfo);k(DevLang-C);k(TargetOS-WINDOWS)%26rd%3Dtrue Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning" Link to comment Share on other sites More sharing options...
Nine Posted August 29, 2021 Share Posted August 29, 2021 Maybe no mouse + no keyboard + no sound = idle ? “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 GIF Animation (cached) Screen Scraping Link to comment Share on other sites More sharing options...
orbs Posted August 29, 2021 Share Posted August 29, 2021 you could rely on Task Scheduler for that, instead of detecting idle time yourself. this is because Task Scheduler respects not only user inactivity as a criteria for idle time, but also resource usage, and most importantly - any programs that set their execution level to any value mentioned here, which prevents Windows from entering sleep mode, activating screen saver, etc. i expect you could call some Win32 API to query Windows if any app execution level has been set as mentioned. however i am unfamiliar with such method, hence my suggestion to use Task Scheduler. recommended read at MSDN here. Link to comment Share on other sites More sharing options...
weirddave Posted August 29, 2021 Author Share Posted August 29, 2021 Thanks for the ideas! I started with task scheduler. I have run into a few problems. The first is that I can't work out how to schedule a task when I come out of idle to turn the amp back on again. Other issues revolve around time. I could potentially use task scheduler to signal a script that idle has been detected, if I can detect coming out of idle as well. no mouse + no KB + no sound should work, tho I haven't found a way to detect if audio is playing. Correction, there's this: Using the screensaver activity might work, I would need to enable one for that tho Don't laugh, but I've only just discovered _Timer_GetIdleTime(). That, coupled with the audio detection, might solve the problem. Happy days Link to comment Share on other sites More sharing options...
spudw2k Posted September 2, 2021 Share Posted September 2, 2021 On 8/29/2021 at 9:30 PM, orbs said: however i am unfamiliar with such method How about this one? _WinAPI_SetThreadExecutionState() Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ 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...
orbs Posted September 2, 2021 Share Posted September 2, 2021 no, that function sets the execution state. i was interested in a method to query the OS if any other program has already set its execution state in a way that requires the system to stay awake. if that was the case, one can assume the system is not idle even if _Timer_GetIdleTime() does return a value that indicates so. Link to comment Share on other sites More sharing options...
junkew Posted September 7, 2021 Share Posted September 7, 2021 https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getlastinputinfo?redirectedfrom=MSDN And I would say just like a tv if "on" for n hours just a messagebox 1 minute before tv is turned off press ok to stay awake. You first have to make your definition of "idle". When I am idle on my system and check what taskmanager is doing with CPU, Memory, ..... I am allways surprised that its 3-5% CPU using because there are still browsers open, virusscanners active, dozens of windows OS processes etc. FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Leendert-Jan Posted September 9, 2021 Share Posted September 9, 2021 (edited) If you are using windows, there is a trigger in event viewer task scheduler that might help. Open event viewer and create a basic task. Begin the Task: On an event Setting Basic Log: System Source: Kernel-Power Event ID: 42 The system is entering sleep. There is also a trigger for when the computer returns from sleep mode, so you can switch the socket back on. Begin the Task: On an event Setting Basic Log: System Source: Power-Troubleshooter Event ID: 1 The system has resumed from sleep. Source: https://superuser.com/questions/321151/how-to-execute-a-script-on-sleep-hibernate-resume-and-shutdown Hope this helps 😃 Edit: It is task scheduler, not event viewer Edited September 9, 2021 by Leendert-Jan Link to comment Share on other sites More sharing options...
seadoggie01 Posted September 9, 2021 Share Posted September 9, 2021 (edited) Someone more familiar with DLL calls/callbacks should look here: https://docs.microsoft.com/en-us/windows/win32/api/powerbase/nf-powerbase-powerregistersuspendresumenotification I think this might notify you when your computer is being suspended/resumed Edit: Or maybe periodically querying this: https://docs.microsoft.com/en-us/windows/win32/api/powerbase/nf-powerbase-callntpowerinformation Edited September 9, 2021 by seadoggie01 All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password manager 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