protected void HandleKeystroke()
        {
            if (String.IsNullOrEmpty(settings.Command))
            {
                return;
            }

            if (settings.Command.Length == 1) // 1 Character is fine
            {
                return;
            }

            string macro = CommandTools.ExtractMacro(settings.Command, 0);

            if (string.IsNullOrEmpty(macro)) // Not a macro, save only first character
            {
                settings.Command = settings.Command[0].ToString();
                SaveSettings();
            }
            else
            {
                if (settings.Command != macro) // Save only one keystroke
                {
                    settings.Command = macro;
                    SaveSettings();
                }
            }
        }
        protected async void SendInput(string inputText)
        {
            if (String.IsNullOrEmpty(inputText))
            {
                return;
            }

            inputRunning = true;
            await Task.Run(() =>
            {
                InputSimulator iis = new InputSimulator();
                string text        = inputText;

                if (settings.IgnoreNewline)
                {
                    text = text.Replace("\r\n", "\n").Replace("\n", "");
                }
                else if (settings.EnterMode)
                {
                    text = text.Replace("\r\n", "\n");
                }

                for (int idx = 0; idx < text.Length && !forceStop; idx++)
                {
                    if (settings.EnterMode && text[idx] == '\n')
                    {
                        iis.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.RETURN);
                    }
                    else if (text[idx] == CommandTools.MACRO_START_CHAR)
                    {
                        string macro = CommandTools.ExtractMacro(text, idx);
                        if (String.IsNullOrWhiteSpace(macro)) // Not a macro, just input the character
                        {
                            InputChar(iis, text[idx]);
                        }
                        else // This is a macro, run it
                        {
                            idx  += macro.Length - 1;
                            macro = macro.Substring(1, macro.Length - 2);

                            HandleMacro(macro);
                        }
                    }
                    else
                    {
                        InputChar(iis, text[idx]);
                    }
                    Thread.Sleep(settings.Delay);
                }
            });

            inputRunning = false;
        }
예제 #3
0
        private void SendInputUp(string inputText)
        {
            var text = inputText;

            for (var idx = 0; idx < text.Length && !ForceStop; idx++)
            {
                var macro = CommandTools.ExtractMacro(text, idx);
                idx  += macro.Length - 1;
                macro = macro.Substring(1, macro.Length - 2);

                HandleMacroUp(macro);
            }
        }
예제 #4
0
        private async void SendInput(string inputText)
        {
            InputRunning = true;
            await Task.Run(() =>
            {
                var text = inputText;

                for (var idx = 0; idx < text.Length && !ForceStop; idx++)
                {
                    var macro = CommandTools.ExtractMacro(text, idx);
                    idx      += macro.Length - 1;
                    macro     = macro.Substring(1, macro.Length - 2);

                    HandleMacro(macro);
                }
            });

            InputRunning = false;
        }
예제 #5
0
        protected string ValidateKeystroke(string keystroke)
        {
            if (String.IsNullOrEmpty(keystroke))
            {
                return(keystroke);
            }

            if (keystroke.Length == 1) // 1 Character is fine
            {
                return(keystroke);
            }

            string macro = CommandTools.ExtractMacro(keystroke, 0);

            if (string.IsNullOrEmpty(macro)) // Not a macro, save only first character
            {
                return(keystroke[0].ToString());
            }
            else
            {
                // Only returns one macro if there is more than one
                return(macro);
            }
        }
        protected async void SendStickyInput(string inputText)
        {
            if (String.IsNullOrEmpty(inputText))
            {
                return;
            }

            inputRunning = true;
            await Task.Run(() =>
            {
                InputSimulator iis = new InputSimulator();
                string text        = inputText;

                if (settings.IgnoreNewline)
                {
                    text = text.Replace("\r\n", "\n").Replace("\n", "");
                }
                else if (Settings.EnterMode)
                {
                    text = text.Replace("\r\n", "\n");
                }

                bool isAutoStopMode = autoStopNum > 0;
                int counter         = autoStopNum;
                while (keyPressed)
                {
                    for (int idx = 0; idx < text.Length; idx++)
                    {
                        if (!keyPressed && !Settings.RunUntilEnd) // Stop as soon as user presses button
                        {
                            break;
                        }
                        if (Settings.EnterMode && text[idx] == '\n')
                        {
                            iis.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.RETURN);
                        }
                        else if (text[idx] == CommandTools.MACRO_START_CHAR)
                        {
                            string macro = CommandTools.ExtractMacro(text, idx);
                            if (String.IsNullOrWhiteSpace(macro)) // Not a macro, just input the character
                            {
                                iis.Keyboard.TextEntry(text[idx]);
                            }
                            else // This is a macro, run it
                            {
                                idx  += macro.Length - 1;
                                macro = macro.Substring(1, macro.Length - 2);

                                HandleMacro(macro);
                            }
                        }
                        else
                        {
                            iis.Keyboard.TextEntry(text[idx]);
                        }
                        Thread.Sleep(Settings.Delay);
                    }
                    if (isAutoStopMode)
                    {
                        counter--; // First decrease, then check if equals zero
                        if (counter <= 0)
                        {
                            keyPressed = false;
                        }
                    }
                }
            });

            inputRunning = false;
        }