private void Press(params Keys[] keys) { keys.ToList().ForEach(key => { Thread.Sleep(1000); Keyboard.KeyPress(key, 10); }); }
internal static void KeyUp(object sender, KeyEventArgs e) { try { e.Handled = true; e.SuppressKeyPress = true; Keyboard.KeyUp(e.KeyCode); if (!Recognize || !PttKeyDown) { return; } if (e.KeyValue != (int)PttKey.ToKey()) { return; } PttKeyDown = false; UI.Ellipse.Fill = new SolidColorBrush(Color.FromRgb(245, 39, 39)); InternalSpeechRecognizer.Engine.RecognizeAsyncStop(); Recognize = false; } catch (Exception ex) { IoQueue.Add(ex); } }
public static async Task <bool> ExecuteCommand(string speechPacket) => await Task.Run(async() => { foreach (var cmd in CommandStorage.AllCommands.Where(cmd => speechPacket == cmd.Key)) { if (cmd.Value.Keys.Length != 0) { if (cmd.Value.Keys.Length > 1) { Keyboard.ShortcutKeys(cmd.Value.Keys.ToKey()); } else { switch (cmd.Value.KeyDownDuration) { case 0: Keyboard.KeyPress(cmd.Value.Keys[0].ToKey()); break; case -1: Keyboard.KeyUp(cmd.Value.Keys[0].ToKey()); break; case int.MaxValue: Keyboard.KeyDown(cmd.Value.Keys[0].ToKey()); break; default: Keyboard.KeyDown(cmd.Value.Keys[0].ToKey()); await Task.Delay(cmd.Value.KeyDownDuration); Keyboard.KeyUp(cmd.Value.Keys[0].ToKey()); break; } } } else if (cmd.Value.MouseKeys.Length != 0) { Mouse.PressButton(cmd.Value.MouseKeys[0]); } if (!string.IsNullOrEmpty(cmd.Value.Response)) { TextToSpeech.Speak(cmd.Value.Response); } return(true); } return(false); });
/// <summary> /// Play a MIDI note inside Warframe. /// </summary> /// <param name="noteId"> The MIDI ID of the note to be played.</param> /// <param name="enableVibrato"> Should we use vibrato to play unplayable notes?.</param> /// <param name="transposeNotes"> Should we transpose unplayable notes?.</param> public static void PlayNote(int noteId, bool enableVibrato, bool transposeNotes) { var shawzinNote = shawzinNotes[noteId]; SetScale(shawzinNote[0]); var stringKey = shawzinStrings[shawzinNote[2]]; var fretKey = shawzinFrets[shawzinNote[1]]; var vibratoKey = shawzinSpecial[0]; if (shawzinNote[3] == 1 && enableVibrato) { KeyHold(vibratoKey, TimeSpan.FromMilliseconds(100)); //Keyboard.KeyDown(vibratoKey); } Keyboard.KeyDown(fretKey); KeyTap(stringKey); Keyboard.KeyUp(fretKey); //Keyboard.KeyUp(vibratoKey); }
internal static void KeyDown(object sender, KeyEventArgs e) { try { e.Handled = true; Keyboard.KeyDown(e.KeyCode); if (Recognize || PttKeyDown) { return; } if (e.KeyValue != (int)PttKey.ToKey()) { return; } PttKeyDown = true; UI.Ellipse.Fill = new SolidColorBrush(Color.FromRgb(39, 245, 46)); InternalSpeechRecognizer.Engine.RecognizeAsync(RecognizeMode.Multiple); Recognize = true; } catch (Exception ex) { IoQueue.Add(ex); } }
/// <summary> /// Hold key for certain amount of time and release. (UNTESTED) /// </summary> /// <param name="key"> The key to be held.</param> /// <param name="time"> The amount of time the key should be held for.</param> public static void KeyHold(Keys key, TimeSpan time) { Keyboard.KeyDown(key); new Timer(state => Keyboard.KeyUp(key), null, time, Timeout.InfiniteTimeSpan); }
/// <summary> /// Tap a key. /// </summary> /// <param name="key"> The key to be tapped.</param> public static void KeyTap(Keys key) { Keyboard.KeyDown(key); Keyboard.KeyUp(key); }