Skip to content

Instantly share code, notes, and snippets.

@kjegru
Last active June 15, 2023 22:54
Show Gist options
  • Save kjegru/1c2951acc41f74f99406aebf33411ade to your computer and use it in GitHub Desktop.
Save kjegru/1c2951acc41f74f99406aebf33411ade to your computer and use it in GitHub Desktop.
# Simple and stupid script that locks the computer and starts filming using the webcam if the mouse coursor moves
# Requires ffmpeg to be installed
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
function mousecheck {
while($true)
{
Start-Sleep -m 500 #added delay
$mouseY = ([System.Windows.Forms.Cursor]::Position.Y ) #read the Y coordinates
$mouseX = ([System.Windows.Forms.Cursor]::Position.X ) #read the X coordinates
if ($mouseX -eq $oldX -and $mouseY -eq $oldY) {
$oldY = $mouseY
$oldX = $mouseX
}
elseif ($firstrun -eq 0) {
$firstrun = 1
$oldY = $mouseY
$oldX = $mouseX
}
else {
rundll32.exe user32.dll, LockWorkStation
Add-Type -AssemblyName System.speech
$alarm = New-Object System.Speech.Synthesis.SpeechSynthesizer
$alarm.speak('DANGER! DANGER! DANGER! INTRUDER ALERT!')
ffmpeg.exe -y -f vfwcap -r 25 -i 0 c:\temp\out.mp4
exit
}
}
}
$firstrun = 0
mousecheck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment