function LetterToNote(g,h)local l="\049\033\050\064\051\052\036\053\037\054\094\055\056\042\057\040\048\113\081\119\087\101\069\114\116\084\121\089\117\105\073\111\079\112\080\097\115\083\100\068\102\103\071\104\072\106\074\107\108\076\122\090\120\099\067\118\086\098\066\110\109"local V="\041\033\064\035\036\037\094\038\042\040"local G=string.char(g)if h then if tonumber(G)then G=string.sub(V,tonumber(G)+1,tonumber(G)+1)else G=string.upper(G)end end local d=string.find(l,G,1,true)if d then return d end end function KeyDown(g)if TextBoxFocused then return end local h=g.KeyCode.Value local l=(InputService:IsKeyDown(303)or InputService:IsKeyDown(304))==not ShiftLock if h>=97 and h<=122 or h>=48 and h<=57 then local g=LetterToNote(h,l)if g then PlayNoteClient(g)end elseif h==8 then Deactivate()elseif h==32 then ToggleSheets()elseif h==13 then ToggleCaps()end end function Input(g)local h=g.UserInputType.Name local l=g.UserInputState.Name if h=="\075\101\121\098\111\097\114\100"then if l=="\066\101\103\105\110"then if FocusLost then FocusLost=false return end KeyDown(g)end end end function TextFocus()TextBoxFocused=true end function TextUnfocus()FocusLost=true TextBoxFocused=false end
----------------------------------
------------FUNCTIONS-------------
----------------------------------

function LetterToNote(key, shift)
	local letterNoteMap = "1!2@34$5%6^78*9(0qQwWeErtTyYuiIoOpPasSdDfgGhHjJklLzZxcCvVbBnm"
	local capitalNumberMap = ")!@#$%^&*("
	local letter = string.char(key)
	if shift then
		if tonumber(letter) then
			-- is a number
			letter = string.sub(capitalNumberMap, tonumber(letter) + 1, tonumber(letter) + 1)
		else
			letter = string.upper(letter)
		end
	end
	local note = string.find(letterNoteMap, letter, 1, true)
	if note then
		return note
	end
end

function KeyDown(Object)
	if TextBoxFocused then
		return
	end
	local key = Object.KeyCode.Value
	local shift = (InputService:IsKeyDown(303) or InputService:IsKeyDown(304)) == not ShiftLock
	if (key >= 97 and key <= 122) or (key >= 48 and key <= 57) then
		-- a letter was pressed
		local note = LetterToNote(key, shift)
		if note then
			PlayNoteClient(note)
		end
	elseif key == 8 then
		-- backspace was pressed
		Deactivate()
	elseif key == 32 then
		-- space was pressed
		ToggleSheets()
	elseif key == 13 then
		-- return was pressed
		ToggleCaps()
	end
end

function Input(Object)
	local type = Object.UserInputType.Name
	local state = Object.UserInputState.Name -- in case I ever add input types
	if type == "Keyboard" then
		if state == "Begin" then
			if FocusLost then -- this is so when enter is pressed in a textbox, it doesn't toggle caps
				FocusLost = false
				return
			end
			KeyDown(Object)
		end
	end
end

function TextFocus()
	TextBoxFocused = true
end
function TextUnfocus()
	FocusLost = true
	TextBoxFocused = false
end
