예제 #1
0
        public override void Do()
        {
            string previous_clipboard = Clipboard.GetText();

            Clipboard.SetText(topaste);
            System.Threading.Thread.Sleep(50);
            KeySender.KeyPress(KeyConverter.Name2Key(KeyConverter.WinFormKey2Name(Keys.LControlKey)));
            KeySender.KeyStroke(KeyConverter.Name2Key(KeyConverter.WinFormKey2Name(Keys.V)));
            KeySender.KeyRelease(KeyConverter.Name2Key(KeyConverter.WinFormKey2Name(Keys.LControlKey)));
            System.Threading.Thread.Sleep(50);
            try
            {
                Clipboard.SetText(previous_clipboard);
            }
            catch
            {
                try
                {
                    Clipboard.SetText("");
                }
                catch { }
            }
        }
예제 #2
0
        public static Macro LoadMacroFile(string[] file)
        {
            if (file.Length > 0)
            {
                string[] args = file[0].Split(' ');

                if (args.Length <= 1)
                {
                    args = new string[2] {
                        args[0], "ÿ"
                    };
                }
                if (args[0].ToLower().Contains("macro"))
                {
                    Macro macro = new Macro(KeyConverter.Name2WinFormKey(args[1]));

                    if (args[0].ToLower().Contains("mouse"))
                    {
                        macro.Type       = MacroType.Mouse;
                        macro.TriggerKey = KeyConverter.Name2WinFormKey("" + args[1][0]);
                    }
                    else if (args[0].ToLower().Contains("winopen"))
                    {
                        macro.Type = MacroType.WinOpen;
                    }
                    else if (args[0].ToLower().Contains("startup"))
                    {
                        macro.Type = MacroType.Startup;
                    }
                    else if (args[0].ToLower().Contains("idle"))
                    {
                        macro.Type = MacroType.IDLE;
                        try { macro.idletime = Int32.Parse(args[1]); }
                        catch { }
                    }
                    else if (args[0].ToLower().Contains("rewrite"))
                    {
                        macro.Type = MacroType.RewriteKeyboard;
                        string[] tmp = args[1].Split("+".ToCharArray());
                        foreach (string k in tmp)
                        {
                            Keys result = KeyConverter.Name2WinFormKey(k);
                            if (result != Keys.None)
                            {
                                macro.TriggerKeys.Add(result);
                            }
                        }
                    }

                    if (args[0].ToLower().Contains("super"))
                    {
                        macro.Override = true;
                    }

                    if (args.Length >= 3)
                    {
                        macro.targetapp = args[2];
                    }

                    for (int i = 1; i < file.Length; i++)
                    {
                        args = file[i].Split(' ');
                        if (args.Length >= 2)
                        {
                            int   time = 0;
                            byte  code = 0;
                            Point P    = Point.Empty;
                            KeySender.MouseButton button;
                            switch (args[0].ToLower())
                            {
                            case "key":
                                code = KeyConverter.Name2Key(args[1]);
                                if (code != 0)
                                {
                                    macro.Add(new ActionKeyStroke(code));
                                }
                                break;

                            case "keydown":
                                code = KeyConverter.Name2Key(args[1]);
                                if (code != 0)
                                {
                                    macro.Add(new ActionKeyPress(code));
                                }
                                break;

                            case "keyup":
                                code = KeyConverter.Name2Key(args[1]);
                                if (code != 0)
                                {
                                    macro.Add(new ActionKeyRelease(code));
                                }
                                break;

                            case "mouse":
                                button = KeyConverter.Name2MouseKey(args[1]);
                                if (args.Length >= 3 && ParsePoint(args[2], ref P))
                                {
                                    macro.Add(new ActionMouseClick(button, P));
                                }
                                else
                                {
                                    macro.Add(new ActionMouseClick(button));
                                }
                                break;

                            case "mousedown":
                                button = KeyConverter.Name2MouseKey(args[1]);
                                if (args.Length >= 3 && ParsePoint(args[2], ref P))
                                {
                                    macro.Add(new ActionMousePress(button, P));
                                }
                                else
                                {
                                    macro.Add(new ActionMousePress(button));
                                }
                                break;

                            case "mouseup":
                                button = KeyConverter.Name2MouseKey(args[1]);
                                if (args.Length >= 3 && ParsePoint(args[2], ref P))
                                {
                                    macro.Add(new ActionMouseRelease(button, P));
                                }
                                else
                                {
                                    macro.Add(new ActionMouseRelease(button));
                                }
                                break;

                            case "sleep":
                                try { time = Int32.Parse(args[1]); }
                                catch { }
                                if (time != 0)
                                {
                                    macro.Add(new ActionSleep(time));
                                }
                                break;

                            case "run":
                                try { macro.Add(new ActionRun(file[i].Substring(4))); }
                                catch { }
                                break;

                            case "paste":
                                try { macro.Add(new ActionPaste(file[i].Substring(6))); }
                                catch { }
                                break;

                            case "close":
                                try { macro.Add(new ActionClose(file[i].Substring(6))); }
                                catch { }
                                break;

                            case "kill":
                                macro.Add(new ActionKill(args[1]));
                                break;
                            }
                        }
                    }

                    return(macro);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
예제 #3
0
        private void OnUserKeyboardPress(object sender, KeyEventArgs e)
        {
            idletime = 0;
            if ((int)e.KeyCode == ActivateKey)
            {
                MacroActivate = true;
                if (testing)
                {
                    string name = WindowManager.GetActiveWindowTitle();
                    string exe  = WindowManager.GetActiveWindowExename();
                    TopMostMessageBox.Show(
                        String.Format(Translations.Get("window_info_result_text"), name, exe),
                        Translations.Get("window_info_result_title"));
                    testing = false;
                }
            }

            switch (e.KeyCode)
            {
            case System.Windows.Forms.Keys.LShiftKey:
            case System.Windows.Forms.Keys.RShiftKey:
            case System.Windows.Forms.Keys.Shift:
            case System.Windows.Forms.Keys.ShiftKey:
                shift = true;
                break;
            }

            while (PressedKeys.Contains(e.KeyCode))
            {
                PressedKeys.Remove(e.KeyCode);
            }

            PressedKeys.Add(e.KeyCode);

            if (KeyHelper.Form_Visible)
            {
                KeyHelper.BoxContent += KeyConverter.WinFormKey2Name(e.KeyCode) + "\n";
                e.Handled             = true;
            }
            else if (ProceedRewriteMacros(e.KeyCode))
            {
                e.Handled = true;
            }

            //Handle french ^ and ¨ key modifiers: êâôëü
            if ((int)e.KeyCode == 221 && !circumflex)
            {
                circumflex = true;
                e.Handled  = true;
                if (shift)
                {
                    diaeresis = true;
                }
            }
            else if (circumflex && !circumflexOn)
            {
                circumflexOn = true;
                switch (e.KeyCode)
                {
                case (System.Windows.Forms.Keys) 221:
                    circumflex = false;
                    diaeresis  = false;
                    if (diaeresis)
                    {
                        KeySender.KeyPress(KeyConverter.Name2Key("Shift"));
                        KeySender.KeyStroke(KeySender.VkKeyScan('^'));
                        KeySender.KeyStroke(KeySender.VkKeyScan('^'));
                        KeySender.KeyRelease(KeyConverter.Name2Key("Shift"));
                    }
                    else
                    {
                        KeySender.KeyStroke(KeySender.VkKeyScan('^'));
                        KeySender.KeyStroke(KeySender.VkKeyScan('^'));
                    }
                    break;

                case System.Windows.Forms.Keys.A:
                case System.Windows.Forms.Keys.E:
                case System.Windows.Forms.Keys.I:
                case System.Windows.Forms.Keys.O:
                case System.Windows.Forms.Keys.U:
                case System.Windows.Forms.Keys.Y:
                    if (diaeresis)
                    {
                        KeySender.KeyPress(KeyConverter.Name2Key("Shift"));
                        KeySender.KeyStroke(KeySender.VkKeyScan('^'));
                        KeySender.KeyRelease(KeyConverter.Name2Key("Shift"));
                    }
                    else
                    {
                        KeySender.KeyStroke(KeySender.VkKeyScan('^'));
                    }
                    circumflex = false;
                    diaeresis  = false;
                    break;

                default:
                    circumflex = false;
                    diaeresis  = false;
                    break;
                }
                circumflexOn = false;
            }
        }