Example #1
0
 private void Press(params Keys[] keys)
 {
     keys.ToList().ForEach(key => {
         Thread.Sleep(1000);
         Keyboard.KeyPress(key, 10);
     });
 }
Example #2
0
        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);
        });