コード例 #1
0
ファイル: SendKeysCommand.cs プロジェクト: zendude213/taskt
        public override void RunCommand(object sender)
        {
            if (v_WindowName != "Current Window")
            {
                ActivateWindowCommand activateWindow = new ActivateWindowCommand
                {
                    v_WindowName = v_WindowName
                };
                activateWindow.RunCommand(sender);
            }

            string textToSend = v_TextToSend.ConvertToUserVariable(sender);

            if (v_EncryptionOption == "Encrypted")
            {
                textToSend = Core.EncryptionServices.DecryptString(textToSend, "TASKT");
            }

            if (textToSend == "{WIN_KEY}")
            {
                User32Functions.KeyDown(System.Windows.Forms.Keys.LWin);
                User32Functions.KeyUp(System.Windows.Forms.Keys.LWin);
            }
            else if (textToSend.Contains("{WIN_KEY+"))
            {
                User32Functions.KeyDown(System.Windows.Forms.Keys.LWin);
                var remainingText = textToSend.Replace("{WIN_KEY+", "").Replace("}", "");

                foreach (var c in remainingText)
                {
                    System.Windows.Forms.Keys key = (System.Windows.Forms.Keys)Enum.Parse(typeof(System.Windows.Forms.Keys), c.ToString());
                    User32Functions.KeyDown(key);
                }

                User32Functions.KeyUp(System.Windows.Forms.Keys.LWin);

                foreach (var c in remainingText)
                {
                    System.Windows.Forms.Keys key = (System.Windows.Forms.Keys)Enum.Parse(typeof(System.Windows.Forms.Keys), c.ToString());
                    User32Functions.KeyUp(key);
                }
            }
            else
            {
                System.Windows.Forms.SendKeys.SendWait(textToSend);
            }



            System.Threading.Thread.Sleep(500);
        }
コード例 #2
0
        public override void RunCommand(object sender)
        {
            var variableWindowName = v_AutomationWindowName.ConvertToUserVariable(sender);

            var searchItem = AutomationElement.RootElement.FindFirst
                                 (TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty,
                                                                            variableWindowName));

            if (searchItem == null)
            {
                throw new Exception("Window not found");
            }

            var requiredHandleName = v_AutomationHandleName.ConvertToUserVariable(sender);
            var requiredItem       = searchItem.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, requiredHandleName));

            var newActivateWindow = new ActivateWindowCommand
            {
                v_WindowName = variableWindowName
            };

            newActivateWindow.RunCommand(sender);

            //get newpoint for now
            var newPoint = requiredItem.GetClickablePoint();

            //send mousemove command
            var newMouseMove = new SendMouseMoveCommand
            {
                v_XMousePosition = newPoint.X.ToString(),
                v_YMousePosition = newPoint.Y.ToString(),
                v_MouseClick     = v_MouseClick
            };

            newMouseMove.RunCommand(sender);
        }
コード例 #3
0
        public override void RunCommand(object sender)
        {
            //activate anything except current window
            if (v_WindowName != "Current Window")
            {
                ActivateWindowCommand activateWindow = new ActivateWindowCommand
                {
                    v_WindowName = v_WindowName
                };
                activateWindow.RunCommand(sender);
            }


            //track all keys down
            var keysDown = new List <System.Windows.Forms.Keys>();

            //run each selected item
            foreach (DataRow rw in v_KeyActions.Rows)
            {
                //get key name
                var keyName = rw.Field <string>("Key");

                //get key action
                var action = rw.Field <string>("Action");

                //parse OEM key name
                string oemKeyString = keyName.Split('[', ']')[1];

                var oemKeyName = (System.Windows.Forms.Keys)Enum.Parse(typeof(System.Windows.Forms.Keys), oemKeyString);


                //"Key Press (Down + Up)", "Key Down", "Key Up"
                switch (action)
                {
                case "Key Press (Down + Up)":
                    //simulate press
                    User32Functions.KeyDown(oemKeyName);
                    User32Functions.KeyUp(oemKeyName);

                    //key returned to UP position so remove if we added it to the keys down list
                    if (keysDown.Contains(oemKeyName))
                    {
                        keysDown.Remove(oemKeyName);
                    }
                    break;

                case "Key Down":
                    //simulate down
                    User32Functions.KeyDown(oemKeyName);

                    //track via keys down list
                    if (!keysDown.Contains(oemKeyName))
                    {
                        keysDown.Add(oemKeyName);
                    }

                    break;

                case "Key Up":
                    //simulate up
                    User32Functions.KeyUp(oemKeyName);

                    //remove from key down
                    if (keysDown.Contains(oemKeyName))
                    {
                        keysDown.Remove(oemKeyName);
                    }

                    break;

                default:
                    break;
                }
            }

            //return key to up position if requested
            if (v_KeyUpDefault.ConvertToUserVariable(sender) == "Yes")
            {
                foreach (var key in keysDown)
                {
                    User32Functions.KeyUp(key);
                }
            }
        }