-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdont-sleep.ps1
More file actions
55 lines (46 loc) · 1.73 KB
/
dont-sleep.ps1
File metadata and controls
55 lines (46 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<#
Copyright (C) 2024 Ali Almahdi
This script is part of Ali's powershell scripts repository on GitHub
Licensed under GNU AGPL-3.0 with Commons Clause License Condition v1.0
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version, with Commons Clause License Condition v1.0.
For commercial licensing inquiries, contact: https://www.ali.ac/contact
#>
<#
.NOTES
Author: Ali Almahdi (https://www.ali.ac)
License: GNU AGPL-3.0 with Commons Clause
Source: https://github.com/almahdi/powershell
Requires: PowerShell 5.1 or higher, Windows
Version: 0.2
#>
<#
This is a simple script that prevents the computer from going to sleep by sending the SCROLLLOCK key.
#>
param(
[int]$Delay = 20,
[switch]$help
)
if ($help) {
Write-Host "Copyright (C) 2024 Ali Almahdi"
Write-Host "Script: dont-sleep.ps1"
Write-Host "Source: https://github.com/almahdi/powershell"
return
}
Write-Host "Preventing the computer from going to sleep... Press CTRL+C to stop the script." -ForegroundColor Green
Write-Host "Using delay of $Delay seconds between SCROLLLOCK toggles." -ForegroundColor Cyan
# Create a new WScript.Shell COM object
$wshell = New-Object -ComObject wscript.shell;
# Infinite loop to keep the script running
while($true) {
# Send the SCROLLLOCK key to toggle it on
$wshell.sendKeys("{SCROLLLOCK}");
# Wait for 300 milliseconds
Start-Sleep -Milliseconds 300
# Send the SCROLLLOCK key to toggle it off
$wshell.sendKeys("{SCROLLLOCK}");
# Wait for specified delay before repeating
Start-Sleep -Seconds $Delay
}