public static bool LoadProfile() { activeKeys.Clear(); Console.Clear(); Console.WriteLine("Type in a config file location. Leave it blank if you'd like to create a new one."); string input = Console.ReadLine(); if (input.Length < 2) { //Return false because it failed. return(false); } //Load string file = System.IO.File.ReadAllText(input); string[] data = file.Split('|'); foreach (string d in data) { string[] dd = d.Split(','); int key = int.Parse(dd[0]); int pitch = int.Parse(dd[1]); //Add it MidiProfileItem item = new MidiProfileItem((Midi.Pitch)pitch, (Keys)key); item.isDown = false; activeKeys.Add(item); } return(true); }
public static void HandleMidiSetup(Midi.Pitch pitch) { //This is run when a key is pressed in setup mode. //Check if we're waiting for a key, or if the user is just pressing keys because they feel like it if (waitingForKeyInput) { //Check if that key already exists. if (FindItemByMidiPitch(pitch) != null) { //It exists! Ignore. return; } waitingForKeyInput = false; //Okay. Deal with it. MidiProfileItem item = new MidiProfileItem(pitch, midiSetupBufferKey); activeKeys.Add(item); bool ok = false; bool cont = false; while (!ok) { Console.Clear(); Console.WriteLine("Done!\r\nWould you like to continue? [Y/N]\r\n"); string input = Console.ReadLine(); if (input.ToLower() == "y") { ok = true; cont = true; } if (input.ToLower() == "n") { ok = true; cont = false; } } //Check if we should continue if (!cont) { //Just change the status to good and continue Console.Clear(); Console.WriteLine("Ready!"); Console.WriteLine("Saved config to " + SaveProfile() + "!"); state = ProgramState.Ready; //Also reverse the last key to be pressed because jank activeKeys[activeKeys.Count - 1].isDown = true; return; } //Ask again PromptForKey(); } }
public static void HandleMidi(Midi.Pitch pitch) { //Handles ALL incoming requests. //Check if we're okay to run the commands. if (state == ProgramState.Setup) { //Change to the setup function HandleMidiSetup(pitch); return; } if (state != ProgramState.Ready) { return; } //Look up the key MidiProfileItem item = FindItemByMidiPitch(pitch); //Check if it's real if (item == null) { //Invalid Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Key " + pitch.ToString() + " pressed, but no valid key was found!"); Console.ForegroundColor = ConsoleColor.White; return; } //Valid key! Toggle it if (item.isDown) { //Pressed. Release it StopKey(item.key); } else { //Not pressed. Press it SendKey(item.key); } //Print Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Key " + pitch.ToString() + " changed. Key " + item.key + " is toggled. Key is now down? " + (!item.isDown).ToString()); //Toggle it item.isDown = !item.isDown; }