# encoding: ascii
# api: powershell
# title: Prevent-Screensaver
# description: Simulate user activity to prevent desktop lock or screensaver for specified period of time
# version: 0.1
# type: script
# author: Dmitry Sotnikov
# license: CC0
# x-poshcode-id: 2901
# x-derived-from-id: 2902
# x-archived: 2011-09-18T11:50:22
# x-published: 2011-08-07T17:30:00
#
#
#########################################################
# Prevent-Screensaver
#########################################################
# This script "presses" a keyboard key every minute
# for specified number of minutes which makes
# Windows "think" you are at your desktop
# so the screensaver does not start and the desktop
# does not get locked. 
#########################################################
# Usage:
# & c:\filepath\Prevent-Screensaver.ps1 -Minutes 120
# Makes the script press "." for 120 minutes.
# Start notepad or another app and put focus there
# to see the dots appear and prevent beeping
########################################################
# (c) Dmitry Sotnikov
# http://dmitrysotnikov.wordpress.com
########################################################

param($minutes = 60)

$myshell = New-Object -com "Wscript.Shell"

for ($i = 0; $i -lt $minutes; $i++) {
  Start-Sleep -Seconds 60
  $myshell.sendkeys(".")
}
