-
Star
(195)
You must be signed in to star a gist -
Fork
(45)
You must be signed in to fork a gist
-
-
Save jamesfreeman959/231b068c3d1ed6557675f21c0e346a9c to your computer and use it in GitHub Desktop.
| # Useful references: | |
| # | |
| # https://superuser.com/questions/992511/emulate-a-keyboard-button-via-the-command-line | |
| # https://ss64.com/vb/sendkeys.html | |
| # https://social.technet.microsoft.com/Forums/windowsserver/en-US/96b339e2-e9da-4802-a66d-be619aeb21ac/execute-function-one-time-in-every-10-mins-in-windows-powershell?forum=winserverpowershell | |
| # https://learn-powershell.net/2013/02/08/powershell-and-events-object-events/ | |
| # | |
| # Future enhancements - use events rather than an infinite loop | |
| $wsh = New-Object -ComObject WScript.Shell | |
| while (1) { | |
| # Send Shift+F15 - this is the least intrusive key combination I can think of and is also used as default by: | |
| # http://www.zhornsoftware.co.uk/caffeine/ | |
| # Unfortunately the above triggers a malware alert on Sophos so I needed to find a native solution - hence this script... | |
| $wsh.SendKeys('+{F15}') | |
| Start-Sleep -seconds 59 | |
| } |
my example from 2 years ago doesn't use powershell at all, but it's a standalone file.
Open source communities benefit a lot from initiatives that make learning and professional development more accessible. The focus on practical education, community support, and building long-term capacity is especially valuable. For organizations looking to strengthen their IT operations and find reliable MSP partners, having the right service provider can also make a big difference in managing technology effectively.
Thanks for sharing this lightweight PowerShell approach using WScript.Shell SendKeys. Using key combinations like {F15} or {NUMLOCK} is a smart way to prevent sleep states without disrupting active typing. We often look into similar automation tricks and tech setups while planning modern display and media setups at Media Walls Ideas. Native scripts like this save a lot of time compared to installing third-party apps!
In general, the script runs beautiful. I had reduced it to the following oneliner, which even adds a random element:
The only problem is: It only doesn't run any more with PowerShell in ConstraintLanguage Mode, it appears this disables the function SendKeys. Does anyone have an alternate how to provide the function while ConstraintLanguage Mode is active?