Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Powershell-based piano using the Console Beep.
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