private void Key_MouseUp(object sender, MouseEventArgs e) { var x = (sender as MusicKey).Pitch; // Stop Timer _Timer.Stop(); _Player.Stop(); // Notify Listeners NotePlayed?.Invoke(this, new NoteEventArgs(x, Math.Max(1, _ElapsedTicks))); }
private static void InputCommand(int noteId, int channel) // Channel is just for identification to invoke a NotePlayed event { Process[] processes = Process.GetProcessesByName("Mordhau-Win64-Shipping"); var modKeys = Control.ModifierKeys; foreach (var modKey in importantModifierKeys) { if ((modKeys & modKey) == modKey) { Thread.Sleep(ConfigManager.GetIntegerProperty(PropertyItem.NoteCooldown)); return; // Drop notes if they're holding any of the important keys, so Mordhau doesn't go nuts // But also sleep the expected amount of time to help avoid situations where they let go of the key and mordhau hasn't noticed yet } } if (AutoConsoleModeFromString(ConfigManager.GetProperty(PropertyItem.ConsoleOpenMode)) == AutoConsoleMode.New) { foreach (Process proc in processes) { PostMessage(proc.MainWindowHandle, WM_KEYDOWN, (int)ConfigManager.GetKeybindProperty(PropertyItem.OpenConsole), 0); } } foreach (char key in consoleCommand) { Enum.TryParse <Keys>("" + key, out Keys tempKey); foreach (Process proc in processes) { PostMessage(proc.MainWindowHandle, WM_KEYDOWN, (int)tempKey, 0); } } foreach (Process proc in processes) { PostMessage(proc.MainWindowHandle, WM_KEYDOWN, (int)Keys.Space, 0); } foreach (char key in noteId.ToString()) { Enum.TryParse <Keys>("NumPad" + key, out Keys tempKey); foreach (Process proc in processes) { PostMessage(proc.MainWindowHandle, WM_KEYDOWN, (int)tempKey, 0); } } foreach (Process proc in processes) { Thread.Sleep(ConfigManager.GetIntegerProperty(PropertyItem.NoteCooldown)); PostMessage(proc.MainWindowHandle, WM_KEYUP, (int)Keys.Enter, 0); NotePlayed?.Invoke(null, channel); } }
private void MidiProc(IntPtr hMidiIn, int wMsg, IntPtr dwInstance, int dwParam1, int dwParam2) { if (wMsg == MM_MIM_DATA) { int note = (dwParam1 >> 8) & 0xff; int status = dwParam1 & 0xf0; if (status == STATUS_NOTE_ON) { NotePlayed?.Invoke(note, true); } else if (status == STATUS_NOTE_OFF) { NotePlayed?.Invoke(note, false); } } }
private static unsafe void MidiCallback(double timeStamp, IntPtr message, ulong messageSize, IntPtr userData) { if (messageSize == 3) { byte *p = (byte *)message.ToPointer(); int status = p[0] & 0xf0; int note = p[1]; int velocity = p[2]; if (status == STATUS_NOTE_OFF || (status == STATUS_NOTE_ON && velocity == 0)) { NotePlayed?.Invoke(note, false); } else if (status == STATUS_NOTE_ON) { NotePlayed?.Invoke(note, true); } Debug.WriteLine($"{status:x2} {note:x2} {velocity:x2}"); } }