Created
August 25, 2017 13:54
-
-
Save Sh1n0g1/a01e5d5117ee08cee7c5164e0d7c80b1 to your computer and use it in GitHub Desktop.
Powershell-based piano using the Console Beep.
This file contains 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
Function Play-ShinoTone{ | |
cls | |
$octave=2 | |
$keytone=@{ # http://pages.mtu.edu/~suits/notefreqs.html | |
'a'=261.63*$octave; # C | |
'w'=277.18*$octave; # C# | |
's'=293.66*$octave; # D | |
'e'=311.13*$octave; # D# | |
'd'=329.63*$octave; # E | |
'f'=349.23*$octave; # F | |
't'=369.99*$octave; # F# | |
'g'=392.00*$octave; # G | |
'y'=415.30*$octave; # G# | |
'h'=440.00*$octave; # A | |
'u'=466.16*$octave; # A# | |
'j'=493.88*$octave; # B | |
'k'=523.25*$octave; # C | |
} | |
Write-Host "TURN YOUR KEYBOARD to PIANO KEYBOARD" | |
Write-Host | |
#1st | |
Write-Host -b 15 -f 00 -n ' ' | |
Write-Host -b 00 -f 15 -n ' ' | |
Write-Host -b 15 -f 00 -n ' ' | |
Write-Host -b 00 -f 15 -n ' ' | |
Write-Host -b 15 -f 00 -n ' | ' | |
Write-Host -b 00 -f 15 -n ' ' | |
Write-Host -b 15 -f 00 -n ' ' | |
Write-Host -b 00 -f 15 -n ' ' | |
Write-Host -b 15 -f 00 -n ' ' | |
Write-Host -b 00 -f 15 -n ' ' | |
Write-Host -b 15 -f 00 ' | ' | |
#2nd | |
Write-Host -b 15 -f 00 -n ' ' | |
Write-Host -b 00 -f 15 -n ' ' | |
Write-Host -b 15 -f 00 -n ' ' | |
Write-Host -b 00 -f 15 -n ' ' | |
Write-Host -b 15 -f 00 -n ' | ' | |
Write-Host -b 00 -f 15 -n ' ' | |
Write-Host -b 15 -f 00 -n ' ' | |
Write-Host -b 00 -f 15 -n ' ' | |
Write-Host -b 15 -f 00 -n ' ' | |
Write-Host -b 00 -f 15 -n ' ' | |
Write-Host -b 15 -f 00 ' | ' | |
#3rd | |
Write-Host -b 15 -f 00 -n ' ' | |
Write-Host -b 00 -f 15 -n ' w ' | |
Write-Host -b 15 -f 00 -n ' ' | |
Write-Host -b 00 -f 15 -n ' e ' | |
Write-Host -b 15 -f 00 -n ' | ' | |
Write-Host -b 00 -f 15 -n ' t ' | |
Write-Host -b 15 -f 00 -n ' ' | |
Write-Host -b 00 -f 15 -n ' y ' | |
Write-Host -b 15 -f 00 -n ' ' | |
Write-Host -b 00 -f 15 -n ' u ' | |
Write-Host -b 15 -f 00 ' | ' | |
#4th | |
Write-Host -b 15 -f 00 -n ' |' | |
Write-Host -b 15 -f 00 -n ' |' | |
Write-Host -b 15 -f 00 -n ' |' | |
Write-Host -b 15 -f 00 -n ' |' | |
Write-Host -b 15 -f 00 -n ' |' | |
Write-Host -b 15 -f 00 -n ' |' | |
Write-Host -b 15 -f 00 -n ' |' | |
Write-Host -b 15 -f 00 ' ' | |
#5th | |
Write-Host -b 15 -f 00 -n ' a |' | |
Write-Host -b 15 -f 00 -n ' s |' | |
Write-Host -b 15 -f 00 -n ' d |' | |
Write-Host -b 15 -f 00 -n ' f |' | |
Write-Host -b 15 -f 00 -n ' g |' | |
Write-Host -b 15 -f 00 -n ' h |' | |
Write-Host -b 15 -f 00 -n ' j |' | |
Write-Host -b 15 -f 00 ' k ' | |
#6th | |
Write-Host -b 15 -f 00 -n ' |' | |
Write-Host -b 15 -f 00 -n ' |' | |
Write-Host -b 15 -f 00 -n ' |' | |
Write-Host -b 15 -f 00 -n ' |' | |
Write-Host -b 15 -f 00 -n ' |' | |
Write-Host -b 15 -f 00 -n ' |' | |
Write-Host -b 15 -f 00 -n ' |' | |
Write-Host -b 15 -f 00 ' ' | |
Write-Host | |
Write-Host | |
Write-Host "Push key for play tone. Or [Esc] to quit, [BackSpace] to Restart." | |
While($True){ | |
$key=(Get-Host).ui.RawUI.ReadKey("NoEcho,IncludeKeyDown") | |
$k=[String]$key.Character | |
If($keytone.Contains($k)){ | |
[console]::beep($keytone[$k],500) | |
Write-Host $k.ToUpper() ' ' -n | |
}ElseIf($key.VirtualKeyCode -eq 27){ #Escape | |
Write-Host | |
Break | |
}ElseIf($key.VirtualKeyCode -eq 8){ #Escape | |
Play-ShinoTone | |
Break | |
} | |
} | |
} | |
Play-ShinoTone |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment