# 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:

```powershell
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.

```powershell
# 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.

```powershell
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
    }
}
```

<p class="callout info">For both you have to save the file under my documents in the following folder and name the file the following:</p>

<p class="callout info">\\Documents\\WindowsPowerShell\\Microsoft.PowerShell\_profile.ps1</p>

### Script Hack

```powershell
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:

<span data-huuid="474416176301448810">To keep the system awake indefinitely, run:</span>

```powershell
.\keep-awake.ps1 -Indefinite
```

<span data-huuid="474416176301448575">To keep the system awake for a specific number of minutes (e.g., 30 minutes), run:</span>

```powershell
.\keep-awake.ps1 -Minutes 30
```