Ejemplo n.º 1
0
        public bool Perform(KeybindDevice device, Keys pressedKey, KeyState state, KeyState lastState, string guid, params object[] args)
        {
            if (args.Length == 0)
            {
                return(false);
            }

            List <Tuple <int, KeyState, int> > inputs = new List <Tuple <int, KeyState, int> >();

            foreach (object arg in args)
            {
                if (!(arg is string str))
                {
                    continue;
                }

                string[] key = str.Trim().Split(' ');

                int index = Array.FindIndex(keynames, k => k.Length == key[0].Length && k.Equals(key[0], StringComparison.InvariantCultureIgnoreCase));

                int delay = DefaultDelay;

                if (key.Length > 1)
                {
                    int keystateindex = 1;

                    if (key.Length > 1)
                    {
                        if (!int.TryParse(key[1], out delay))
                        {
                            delay = DefaultDelay;
                        }
                        else
                        {
                            keystateindex++;
                        }
                    }

                    if (key.Length > keystateindex)
                    {
                        inputs.Add(new Tuple <int, KeyState, int>(index, key[keystateindex].Length == 4 && (key[keystateindex].Equals("make", StringComparison.InvariantCultureIgnoreCase) || key[keystateindex].Equals("down", StringComparison.InvariantCultureIgnoreCase)) ? KeyState.Make : KeyState.Break, delay));

                        continue;
                    }
                }

                inputs.Add(new Tuple <int, KeyState, int>(index, KeyState.Make, delay));
                inputs.Add(new Tuple <int, KeyState, int>(index, KeyState.Break, delay));
            }

            foreach (Tuple <int, KeyState, int> input in inputs)
            {
                InputSimulation.SetKeyState(keys[input.Item1], input.Item2);

                InputSimulation.Sleep(input.Item3);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public bool Perform(KeybindDevice device, Keys key, KeyState state, KeyState lastState, string guid, params object[] args)
        {
            AudioDeviceAction action = AudioDeviceAction.ToggleMute;

            if (args.Length > 0 && args[0] is string str)
            {
                if (str.Length == ToggleMute.Length && str.Equals(ToggleMute))
                {
                    action = AudioDeviceAction.ToggleMute;
                }
                else if (str.Length == Mute.Length && str.Equals(Mute))
                {
                    action = AudioDeviceAction.Mute;
                }
                else if (str.Length == Unmute.Length && str.Equals(Unmute))
                {
                    action = AudioDeviceAction.Unmute;
                }
                else if (str.Length == SetVolume.Length && str.Equals(SetVolume) || str.Length == Volume.Length && str.Equals(Volume))
                {
                    action = AudioDeviceAction.SetVolume;
                }
                else
                {
                    return(false);
                }
            }

            CoreAudioDevice mic = Audio.Controller.DefaultCaptureDevice;

            Audio.Speech.SpeakAsyncCancelAll();

            if (action == AudioDeviceAction.ToggleMute || action == AudioDeviceAction.Mute || action == AudioDeviceAction.Unmute)
            {
                bool mute = action == AudioDeviceAction.ToggleMute ? !mic.IsMuted : action == AudioDeviceAction.Mute ? true : false;

                mic.Mute(mute);

                Audio.Speech.SpeakAsync($"Microphone {(mute ? "muted" : "activated")}");
                //Audio.Speech.SpeakAsync(mute ? "Muted" : "Activated");
            }
            else if (action == AudioDeviceAction.SetVolume)
            {
                if (args.Length < 2 || !(args[1] is long volume) || volume < 0 || volume > 100)
                {
                    return(false);
                }

                mic.Volume = volume;

                Audio.Speech.SpeakAsync($"Microphone volume set to {volume}");
            }

            return(true);
        }