by Technicality » Mon Mar 01, 2021 1:48 am
Here's the code for the script if you'd rather just copy/paste it into your own script
*Note* this will only work if the encoding of the ahk file is UTF-8-BOM (encoding can be changed in notepad++)
#NoEnv
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
#singleinstance force
ListLines Off
Process, Priority, , R
SetBatchLines, -1
SetKeyDelay, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
Gui, Add, Text,, Paste Sheet Music Below
Gui, Add, Edit, R10 w400 vPianoCode
Gui, SongProgress:Add, Edit, w400 h300 vSheetProgress
Gui, Add, Text,, Copy/paste sheet music into the box, press F1 to load the song, F2 to start playing
Gui, Add, Text,, F3 will close the application
Gui, Add, Text, C , Version 0.2
StringCaseSense, On
Keys := []
noteOrSleep := []
nkey = 0
global notif := false
marked := false
nchord := ""
;~~~~~~~~~Try Out Different Delays~~~~~~~~~
Delay = 80
;~~~~~~~~~Try Out Different Delays~~~~~~~~~
rest = 0
count = 1
global isSleep := false
BlockedKeys := false
counter := new SecondCounter
recorder := new RecordCounter
Gui, Show
global Delay2 := Delay / 2
global Delay3 := 5
global Delay4 := Delay / 10
F1::
global isSleep, notif
Gui, Submit, Nohide
Loop, parse, PianoCode
{
var = %A_Loopfield%
prevKey := nkey
if((var = "1") || (var = "2") || (var = "3") || (var = "4") || (var = "5") || (var = "6") || (var = "7") || (var = "8") || (var = "▲") || (var = "▼") || (var = "[") || (var = "]") || (var = ")") || (var = "(") || (var = "")){
next := true
}
if (next){
if ((var = "▼") || (var = ")") || (var = "[")) {
nkey = 9
if (nChord > ""){
Keys.Push(nChord)
Keys.Push(nKey)
nChord := ""
Skip := true
}else{
Keys.Push(nKey)
Skip := true
nChord := ""
}
}
else if ((var = "▲") || (var = "(") || (var = "]")) {
nkey = 0
if (nChord > ""){
Keys.Push(nChord)
Keys.Push(nKey)
nChord := ""
Skip := true
}else{
Keys.Push(nKey)
Skip := true
marked := true
nChord := ""
}
}
else if (var = 1){
nkey = 1
}
else if (var = 2){
nkey = 2
}
else if (var = 3){
nkey = 3
}
else if (var = 4){
nkey = 4
}
else if (var = 5){
nkey = 5
}
else if (var = 6){
nkey = 6
}
else if (var = 7){
nkey = 7
}
else if (var = 8){
nkey = 8
}
else if (var = ""){
nkey =
notif := true
}
if(!Skip){
if(!marked){
if (notif = true){
if(nChord > ""){
Keys.Push(nChord)
}
notif := false
nChord := ""
}else{
nChord := nChord . nkey
}
}
}
Skip := false
}
next := false
marked := false
}
klen := Keys.Length()
nlen := NoteOrSleep.Length()
Gui, Font, s12, Verdana
;Gui, SongProgress:Show,,Sheet Music
Loop %klen%
{
toSheet := Keys[A_Index]
if StrLen(toSheet) > 1
{
toText .= "[" . Keys[A_Index] . "]" . " "
}else{
toText .= Keys[A_Index] . " "
}
}
;GuiControl,SongProgress:, SheetProgress, %toText%
return
F2::
klen := Keys.Length()
OctaveMode := !OctaveMode
BlockedKeys := !BlockedKeys
test := Keys[count]
if(test = 9){
SendInput {9 Up}
SendInput {9 Down}
count++
}
if(test = 0){
SendInput {0 Up}
SendInput {0 Down}
count++
}
return
$1::
charValue = 1
if(!BlockedKeys)
{
SendInput {1 down}
}
if (OctaveMode)
{
SendInput {1 down}
pval := Keys[count]
pval := StrReplace(pval, charValue,,,1)
Keys[count] := pval
if(pval = ""){
v1 := Keys[count + 1]
v2 := Keys[count + 2]
if(v1 = 9){
SendInput {9 up}
count++
if (counter.count > 0){
dif := Delay - (counter.count * 10)
Sleep, dif
}
if(v2 = 0){
count++
}else{
SendInput {9 Up}
SendInput {9 Down}
counter.Stop()
counter.Start()
if(v2 = 9){
count++
counter.Stop()
Sleep, Delay2
SendInput {9 Up}
Sleep, Delay2
SendInput {9 Down}
counter.Start()
}
}
}
if(v1 = 0){
SendInput {0 up}
count++
if (counter.count > 0){
dif := Delay - (counter.count * 10)
Sleep, dif
}
if (v2 = 9){
count++
}else{
SendInput {0 Up}
SendInput {0 Down}
counter.Stop()
counter.Start()
if(v2 = 0){
count++
counter.Stop()
Sleep, Delay2
SendInput {0 Up}
Sleep, Delay2
SendInput {0 Down}
counter.Start()
}
}
}
count++
}
}
return
$1 Up::
SendInput {1 Up}
return
$2::
charValue = 2
if(!BlockedKeys)
{
SendInput {2 down}
}
if (OctaveMode)
{
SendInput {2 down}
pval := Keys[count]
pval := StrReplace(pval, charValue,,,1)
Keys[count] := pval
if(pval = ""){
v1 := Keys[count + 1]
v2 := Keys[count + 2]
if(v1 = 9){
SendInput {9 up}
count++
if (counter.count > 0){
dif := Delay - (counter.count * 10)
Sleep, dif
}
if(v2 = 0){
count++
}else{
SendInput {9 Up}
SendInput {9 Down}
counter.Stop()
counter.Start()
if(v2 = 9){
count++
counter.Stop()
Sleep, Delay2
SendInput {9 Up}
Sleep, Delay2
SendInput {9 Down}
counter.Start()
}
}
}
if(v1 = 0){
SendInput {0 up}
count++
if (counter.count > 0){
dif := Delay - (counter.count * 10)
Sleep, dif
}
if (v2 = 9){
count++
}else{
SendInput {0 Up}
SendInput {0 Down}
counter.Stop()
counter.Start()
if(v2 = 0){
count++
counter.Stop()
Sleep, Delay2
SendInput {0 Up}
Sleep, Delay2
SendInput {0 Down}
counter.Start()
}
}
}
count++
}
}
return
$2 Up::
SendInput {2 Up}
return
$3::
charValue = 3
if(!BlockedKeys)
{
SendInput {3 down}
}
if (OctaveMode)
{
SendInput {3 down}
pval := Keys[count]
pval := StrReplace(pval, charValue,,,1)
Keys[count] := pval
if(pval = ""){
v1 := Keys[count + 1]
v2 := Keys[count + 2]
if(v1 = 9){
SendInput {9 up}
count++
if (counter.count > 0){
dif := Delay - (counter.count * 10)
Sleep, dif
}
if(v2 = 0){
count++
}else{
SendInput {9 Up}
SendInput {9 Down}
counter.Stop()
counter.Start()
if(v2 = 9){
count++
counter.Stop()
Sleep, Delay2
SendInput {9 Up}
Sleep, Delay2
SendInput {9 Down}
counter.Start()
}
}
}
if(v1 = 0){
SendInput {0 up}
count++
if (counter.count > 0){
dif := Delay - (counter.count * 10)
Sleep, dif
}
if (v2 = 9){
count++
}else{
SendInput {0 Up}
SendInput {0 Down}
counter.Stop()
counter.Start()
if(v2 = 0){
count++
counter.Stop()
Sleep, Delay2
SendInput {0 Up}
Sleep, Delay2
SendInput {0 Down}
counter.Start()
}
}
}
count++
}
}
return
$3 Up::
SendInput {3 Up}
return
$4::
charValue = 4
if(!BlockedKeys)
{
SendInput {4 down}
}
if (OctaveMode)
{
SendInput {4 down}
pval := Keys[count]
pval := StrReplace(pval, charValue,,,1)
Keys[count] := pval
if(pval = ""){
v1 := Keys[count + 1]
v2 := Keys[count + 2]
if(v1 = 9){
SendInput {9 up}
count++
if (counter.count > 0){
dif := Delay - (counter.count * 10)
Sleep, dif
}
if(v2 = 0){
count++
}else{
SendInput {9 Up}
SendInput {9 Down}
counter.Stop()
counter.Start()
if(v2 = 9){
count++
counter.Stop()
Sleep, Delay2
SendInput {9 Up}
Sleep, Delay2
SendInput {9 Down}
counter.Start()
}
}
}
if(v1 = 0){
SendInput {0 up}
count++
if (counter.count > 0){
dif := Delay - (counter.count * 10)
Sleep, dif
}
if (v2 = 9){
count++
}else{
SendInput {0 Up}
SendInput {0 Down}
counter.Stop()
counter.Start()
if(v2 = 0){
count++
counter.Stop()
Sleep, Delay2
SendInput {0 Up}
Sleep, Delay2
SendInput {0 Down}
counter.Start()
}
}
}
count++
}
}
return
$4 Up::
SendInput {4 Up}
return
$5::
charValue = 5
if(!BlockedKeys)
{
SendInput {5 down}
}
if (OctaveMode)
{
SendInput {5 down}
pval := Keys[count]
pval := StrReplace(pval, charValue,,,1)
Keys[count] := pval
if(pval = ""){
v1 := Keys[count + 1]
v2 := Keys[count + 2]
if(v1 = 9){
SendInput {9 up}
count++
if (counter.count > 0){
dif := Delay - (counter.count * 10)
Sleep, dif
}
if(v2 = 0){
count++
}else{
SendInput {9 Up}
SendInput {9 Down}
counter.Stop()
counter.Start()
if(v2 = 9){
count++
counter.Stop()
Sleep, Delay2
SendInput {9 Up}
Sleep, Delay2
SendInput {9 Down}
counter.Start()
}
}
}
if(v1 = 0){
SendInput {0 up}
count++
if (counter.count > 0){
dif := Delay - (counter.count * 10)
Sleep, dif
}
if (v2 = 9){
count++
}else{
SendInput {0 Up}
SendInput {0 Down}
counter.Stop()
counter.Start()
if(v2 = 0){
count++
counter.Stop()
Sleep, Delay2
SendInput {0 Up}
Sleep, Delay2
SendInput {0 Down}
counter.Start()
}
}
}
count++
}
}
return
$5 Up::
SendInput {5 Up}
return
$6::
charValue = 6
if(!BlockedKeys)
{
SendInput {6 down}
}
if (OctaveMode)
{
SendInput {6 down}
pval := Keys[count]
pval := StrReplace(pval, charValue,,,1)
Keys[count] := pval
if(pval = ""){
v1 := Keys[count + 1]
v2 := Keys[count + 2]
if(v1 = 9){
SendInput {9 up}
count++
if (counter.count > 0){
dif := Delay - (counter.count * 10)
Sleep, dif
}
if(v2 = 0){
count++
}else{
SendInput {9 Up}
SendInput {9 Down}
counter.Stop()
counter.Start()
if(v2 = 9){
count++
counter.Stop()
Sleep, Delay2
SendInput {9 Up}
Sleep, Delay2
SendInput {9 Down}
counter.Start()
}
}
}
if(v1 = 0){
SendInput {0 up}
count++
if (counter.count > 0){
dif := Delay - (counter.count * 10)
Sleep, dif
}
if (v2 = 9){
count++
}else{
SendInput {0 Up}
SendInput {0 Down}
counter.Stop()
counter.Start()
if(v2 = 0){
count++
counter.Stop()
Sleep, Delay2
SendInput {0 Up}
Sleep, Delay2
SendInput {0 Down}
counter.Start()
}
}
}
count++
}
}
return
$6 Up::
SendInput {6 Up}
return
$7::
charValue = 7
if(!BlockedKeys)
{
SendInput {7 down}
}
if (OctaveMode)
{
SendInput {7 down}
pval := Keys[count]
pval := StrReplace(pval, charValue,,,1)
Keys[count] := pval
if(pval = ""){
v1 := Keys[count + 1]
v2 := Keys[count + 2]
if(v1 = 9){
SendInput {9 up}
count++
if (counter.count > 0){
dif := Delay - (counter.count * 10)
Sleep, dif
}
if(v2 = 0){
count++
}else{
SendInput {9 Up}
SendInput {9 Down}
counter.Stop()
counter.Start()
if(v2 = 9){
count++
counter.Stop()
Sleep, Delay2
SendInput {9 Up}
Sleep, Delay2
SendInput {9 Down}
counter.Start()
}
}
}
if(v1 = 0){
SendInput {0 up}
count++
if (counter.count > 0){
dif := Delay - (counter.count * 10)
Sleep, dif
}
if (v2 = 9){
count++
}else{
SendInput {0 Up}
SendInput {0 Down}
counter.Stop()
counter.Start()
if(v2 = 0){
count++
counter.Stop()
Sleep, Delay2
SendInput {0 Up}
Sleep, Delay2
SendInput {0 Down}
counter.Start()
}
}
}
count++
}
}
return
$7 Up::
SendInput {7 Up}
return
$8::
charValue = 8
if(!BlockedKeys)
{
SendInput {8 down}
}
if (OctaveMode)
{
SendInput {8 down}
pval := Keys[count]
pval := StrReplace(pval, charValue,,,1)
Keys[count] := pval
if(pval = ""){
v1 := Keys[count + 1]
v2 := Keys[count + 2]
if(v1 = 9){
SendInput {9 up}
count++
if (counter.count > 0){
dif := Delay - (counter.count * 10)
Sleep, dif
}
if(v2 = 0){
count++
}else{
SendInput {9 Up}
SendInput {9 Down}
counter.Stop()
counter.Start()
if(v2 = 9){
count++
counter.Stop()
Sleep, Delay2
SendInput {9 Up}
Sleep, Delay2
SendInput {9 Down}
counter.Start()
}
}
}
if(v1 = 0){
SendInput {0 up}
count++
if (counter.count > 0){
dif := Delay - (counter.count * 10)
Sleep, dif
}
if (v2 = 9){
count++
}else{
SendInput {0 Up}
SendInput {0 Down}
counter.Stop()
counter.Start()
if(v2 = 0){
count++
counter.Stop()
Sleep, Delay2
SendInput {0 Up}
Sleep, Delay2
SendInput {0 Down}
counter.Start()
}
}
}
count++
}
}
return
$8 Up::
SendInput {8 Up}
return
$9::
SendInput {9 Down}
return
$9 Up::
SendInput {9 Up}
return
$0::
SendInput {0 Down}
return
$0 Up::
SendInput {0 Up}
return
class SecondCounter {
__New() {
this.interval := 1
this.count := 0
; Tick() has an implicit parameter "this" which is a reference to
; the object, so we need to create a function which encapsulates
; "this" and the method to call:
this.timer := ObjBindMethod(this, "Tick")
}
Start() {
; Known limitation: SetTimer requires a plain variable reference.
timer := this.timer
this.count := 0
SetTimer % timer, % this.interval
;ToolTip % "Counter started"
}
Stop() {
; To turn off the timer, we must pass the same object as before:
timer := this.timer
this.count := 0
SetTimer % timer, Off
;ToolTip % "Counter stopped at " this.count
}
; In this example, the timer calls this method:
Tick() {
global Delay2, Delay3
this.count++
if (this.count = Delay3){
SendInput {9 Up}
SendInput {0 Up}
}
if (this.count >= Delay4){
this.Stop()
this.count := 0
}
;ToolTip % this.count
}
}
F3::ExitApp
return
GuiClose:
ExitApp