Skip to main content

Caffeine Hack - Got caught with Caffeine installed

Hack

Click Start, then type Powershell and it should show up.

Type notepad $profile to open your default profile.

This will likely be blank if this is the first time doing this.

Paste the following code:

function idle {
	$wshell = New-Object -ComObject wscript.shell;
	"Press CTRL+C to cancel."
	while ($true) {
		$wshell.SendKeys('+')
		Sleep 60
	}
}

Close PowerShell, then re-open it (see step one).

Type idle and hit enter.

Optional: autorun you can add idle to line 9, and when opening PowerShell it will auto run

This function just presses the shift key every minute. It's less intrusive than mouse wigglers..

Updated Version

Save this to your profile, and then you can run it indefinitely using idle or set a duration in minutes by adding it at the end idle 28800.

You can even have it do the math for you. So 60 mins * 8 hours would be idle (60*8).

You can get even fancier if you know what time you need to clock out.

# If you stop working at 5pm (17:00) then you could use this:
$peaceout = (get-date 17:00)

idle ($peaceout - (get-date)).TotalMinutes

This part goes in your profile. Remember, if you make changes to your profile you will need to close and reopen any PowerShell terminals for them to pick up the changes.

function idle {
    param(
    	[int]$Duration = -1 # Duration in Minutes
    )
    $wshell = New-Object -ComObject wscript.shell;
    
    'Press CTRL+C to cancel.'
    $idle = $true
    
    while ($idle) {
    	$wshell.SendKeys('+')
    	if ($Duration -eq 0) {
    		$idle = $false
    		'Time Expired.'
    		break
    	}
    	elseif ($Duration -gt 0) {
    		write-host -NoNewline "`r$Duration min(s) remaining."
    		$Duration--
    	}
    
    	Start-Sleep 60
    }
}

For both you have to save the file under my documents in the following folder and name the file the following:

\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

Script Hack

param(
    [switch]$Indefinite,
    [int]$Minutes = 0
)

if ($Indefinite) {
    Write-Host "Keeping system awake indefinitely. Press Ctrl+C to stop."
    while ($true) {
        [System.Windows.Forms.Cursor]::Position
        Start-Sleep -Seconds 60
    }
} elseif ($Minutes -gt 0) {
    Write-Host "Keeping system awake for $Minutes minutes. This window will close automatically when done."
    $endTime = (Get-Date).AddMinutes($Minutes)
    while ((Get-Date) -lt $endTime) {
        [System.Windows.Forms.Cursor]::Position
        Start-Sleep -Seconds 60
    }
    Write-Host "Time's up!"
} else {
    Write-Host "Please specify either -Indefinite or -Minutes <number of minutes>."
}

To Use the Script:

To keep the system awake indefinitely, run:

.\keep-awake.ps1 -Indefinite

To keep the system awake for a specific number of minutes (e.g., 30 minutes), run:

.\keep-awake.ps1 -Minutes 30