Example #1
0
        public bool ExecuteAction(ActionProgramRun ap, BaseUtils.EnhancedSendKeysParser.IAdditionalKeyParser akp)       // additional parser
        {
            string    keys;
            Variables statementvars;

            if (FromString(userdata, out keys, out statementvars))
            {
                string    errlist = null;
                Variables vars    = ap.functions.ExpandVars(statementvars, out errlist);

                if (errlist == null)
                {
                    int    delay               = vars.Exists(DelayID) ? vars[DelayID].InvariantParseInt(DefaultDelay) : (ap.VarExist(globalvarDelay) ? ap[globalvarDelay].InvariantParseInt(DefaultDelay) : DefaultDelay);
                    int    updelay             = vars.Exists(UpDelayID) ? vars[UpDelayID].InvariantParseInt(DefaultDelay) : (ap.VarExist(globalvarUpDelay) ? ap[globalvarUpDelay].InvariantParseInt(DefaultDelay) : DefaultDelay);
                    int    shiftdelay          = vars.Exists(ShiftDelayID) ? vars[ShiftDelayID].InvariantParseInt(DefaultDelay) : (ap.VarExist(globalvarShiftDelay) ? ap[globalvarShiftDelay].InvariantParseInt(DefaultDelay) : DefaultDelay);
                    string process             = vars.Exists(ProcessID) ? vars[ProcessID] : (ap.VarExist(globalvarProcessID) ? ap[globalvarProcessID] : "");
                    string silentonerrors      = vars.Exists(SilentOnError) ? vars[SilentOnError] : (ap.VarExist(globalvarSilentOnErrors) ? ap[globalvarSilentOnErrors] : "0");
                    string announciateonerrors = vars.Exists(AnnounciateOnError) ? vars[AnnounciateOnError] : (ap.VarExist(globalvarAnnounciateOnError) ? ap[globalvarAnnounciateOnError] : "0");

                    string res = BaseUtils.EnhancedSendKeys.SendToProcess(keys, delay, shiftdelay, updelay, process, akp);

                    if (res.HasChars())
                    {
                        if (silentonerrors.Equals("2") || (errorsreported.Contains(res) && silentonerrors.Equals("1")))
                        {
                            System.Diagnostics.Debug.WriteLine("Swallow key error " + res);
                            ap.actioncontroller.TerminateAll();
                        }
                        else
                        {
                            errorsreported.Add(res);

                            if (announciateonerrors.Equals("1"))
                            {
                                string culture               = ap.VarExist(ActionSay.globalvarspeechculture) ? ap[ActionSay.globalvarspeechculture] : "Default";
                                System.IO.MemoryStream ms    = ap.actioncontroller.SpeechSynthesizer.Speak("Cannot press key due to " + res, culture, "Default", 0);
                                AudioQueue.AudioSample audio = ap.actioncontroller.AudioQueueSpeech.Generate(ms);
                                ap.actioncontroller.AudioQueueSpeech.Submit(audio, 80, AudioQueue.Priority.Normal);
                            }

                            ap.ReportError(res);
                        }
                    }
                }
                else
                {
                    ap.ReportError(errlist);
                }
            }
            else
            {
                ap.ReportError("Key command line not in correct format");
            }

            return(true);
        }
Example #2
0
        }                                                               // Tell dragger no resizing.

        public void Init(Icon i, bool showprocess,
                         string separ                 = " ", // and separ between entries
                         string keystring             = "",  // current key string
                         string process               = "",  // empty means program default, return empty back
                         int defdelay                 = 50,  // -1 means program default, return -1 back
                         bool allowkeysedit           = false,
                         List <string> additionalkeys = null,
                         BaseUtils.EnhancedSendKeysParser.IAdditionalKeyParser parser = null)
        {
            var enumlist = new Enum[] { ECIDs.KeyForm, ECIDs.KeyForm_radioButtonUp, ECIDs.KeyForm_radioButtonDown, ECIDs.KeyForm_radioButtonPress, ECIDs.KeyForm_checkBoxShift, ECIDs.KeyForm_checkBoxCtrl, ECIDs.KeyForm_checkBoxAlt, ECIDs.KeyForm_checkBoxKey, ECIDs.KeyForm_labelNextDelay, ECIDs.KeyForm_labelSelKeys, ECIDs.KeyForm_labelDelay, ECIDs.KeyForm_labelSendTo, ECIDs.KeyForm_buttonReset, ECIDs.KeyForm_labelKeys, ECIDs.KeyForm_buttonDelete, ECIDs.KeyForm_buttonNext, ECIDs.KeyForm_buttonTest };

            BaseUtils.Translator.Instance.TranslateControls(this, enumlist);

            if (i != null)
            {
                Icon = i;
            }

            seperator = separ;

            textBoxKeys.Text = keystring;
            curinsertpoint   = keystring.Length;

            textBoxSendTo.Text    = process.Alt(DefaultProcessID);
            textBoxNextDelay.Text = textBoxDelay.Text = defdelay != DefaultDelayID?defdelay.ToStringInvariant() : "Default";

            radioButtonPress.Checked = true;

            if (additionalkeys != null)
            {
                comboBoxKeySelector.Items.AddRange(additionalkeys);
            }
            comboBoxKeySelector.Items.AddRange(KeyObjectExtensions.KeyListString());

            additionalkeyparser = parser;

            //System.Diagnostics.Debug.WriteLine(String.Join(",",KeyObjectExtensions.VKeyList()));
            comboBoxKeySelector.Text = "";
            comboBoxKeySelector.SelectedIndexChanged += new System.EventHandler(this.comboBoxKeySelector_SelectedIndexChanged);

            if (!showprocess)
            {
                textBoxNextDelay.Visible = panelRadio.Visible = labelNextDelay.Visible = labelDelay.Visible = textBoxDelay.Visible = labelSendTo.Visible = textBoxSendTo.Visible = buttonTest.Visible = false;

                int d = textBoxKeys.Top - textBoxDelay.Top;
                foreach (Control c in new Control[] { buttonReset, buttonDelete, buttonNext, textBoxKeys, labelKeys })
                {
                    c.Top -= d; // shift down
                }
                d += 40;        // cause of the Send
                foreach (Control c in new Control[] { buttonOK, buttonCancel })
                {
                    c.Top -= d;
                }
                panelOuter.Height -= d;
                this.Height       -= d;
            }

            //System.Diagnostics.Debug.WriteLine("T" + textBoxKeys.Text + " at " + curinsertpoint + " >" + textBoxSendTo.Text);

            bool  border = true;
            Theme theme  = Theme.Current;

            if (theme != null)  // paranoid
            {
                border = theme.ApplyDialog(this);
            }

            labelCaption.Visible = !border;

            AddMF();
            AddMF();

            if (allowkeysedit)
            {
                textBoxKeys.ReadOnly = false;
            }

            DisplayKeyString();

            labelCaption.Text = this.Text;
        }
Example #3
0
        static public string Menu(Form parent, System.Drawing.Icon ic, string userdata, List <string> additionalkeys, BaseUtils.EnhancedSendKeysParser.IAdditionalKeyParser additionalparser)
        {
            Variables vars;
            string    keys;

            FromString(userdata, out keys, out vars);

            ExtendedControls.KeyForm kf = new ExtendedControls.KeyForm();
            int    defdelay             = vars.Exists(DelayID) ? vars[DelayID].InvariantParseInt(DefaultDelay) : ExtendedControls.KeyForm.DefaultDelayID;
            string process = vars.Exists(ProcessID) ? vars[ProcessID] : "";

            kf.Init(ic, true, " ", keys, process, defdelay: defdelay, additionalkeys: additionalkeys, parser: additionalparser);      // process="" default, defdelay = DefaultDelayID default

            if (kf.ShowDialog(parent) == DialogResult.OK)
            {
                Variables vlist = new Variables();

                if (kf.DefaultDelay != ExtendedControls.KeyForm.DefaultDelayID)                                       // only add these into the command if set to non default
                {
                    vlist[DelayID] = kf.DefaultDelay.ToStringInvariant();
                }
                if (kf.ProcessSelected.Length > 0)
                {
                    vlist[ProcessID] = kf.ProcessSelected;
                }

                return(ToString(kf.KeyList, vlist));
            }
            else
            {
                return(null);
            }
        }