Ejemplo n.º 1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            s_windowHandle = new System.Windows.Interop.WindowInteropHelper(Application.Current.MainWindow).Handle;
            System.Windows.Interop.HwndSource.FromHwnd(s_windowHandle).AddHook(RunOnUiThread);

            s_mainWin = this;
            this.comboBoxRecordedUi.ItemsSource = RecordedUiTask.s_listRecordedUi;
            this.treeUiPath.ItemsSource         = UiTreeNode.s_uiTreeNodes;

            ConstVariables.InitVk2StringMap();

            AppInsights.LogEvent("Window_Loaded");
        }
Ejemplo n.º 2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            gridXPath.RowDefinitions[2].Height = new GridLength(TabCodeHeight);
            windowHandle = new System.Windows.Interop.WindowInteropHelper(Application.Current.MainWindow).Handle;
            System.Windows.Interop.HwndSource.FromHwnd(windowHandle).AddHook(XmlNodePathRecorder.ProcessMessage);

            s_mainWin = this;
            this.comboBoxRecordedUi.ItemsSource = s_listRecordedUi;

            ConstVariables.InitVk2StringMap();

            timer = new System.Timers.Timer(100)
            {
                Enabled = true, AutoReset = false
            };
            timer.Elapsed += InitMouseKeyboard;
            timer.Start();
        }
Ejemplo n.º 3
0
        public static List <string> GetDecodedKeyboardInput(string strBase64, bool bCapsLock, bool bNumLock, bool ScrollLock)
        {
            byte[] data = Convert.FromBase64String(strBase64);

            int  i     = 0;
            bool shift = false;

            StringBuilder sb    = new StringBuilder();
            List <string> lines = new List <string>();

            while (i < data.Length / 2)
            {
                int n1 = i * 2;
                int n2 = i * 2 + 1;
                i++;

                bool        bIsKeyDown = data[n1] == 0;
                VirtualKeys vk         = (VirtualKeys)data[n2];

                if (vk == VirtualKeys.VK_SHIFT || vk == VirtualKeys.VK_LSHIFT || vk == VirtualKeys.VK_RSHIFT)
                {
                    shift = bIsKeyDown;
                    continue;
                }

                if (vk == VirtualKeys.VK_CAPITAL)
                {
                    if (bIsKeyDown)
                    {
                        bCapsLock = !bCapsLock;
                    }
                    continue;
                }

                char ch = ConstVariables.Vk2char((int)vk, shift || bCapsLock);

                // Create lines like winElem1.SendKeys(Keys.Control+ "a" + Keys.Control);
                bool bOutputVK = false;

                if (vk == VirtualKeys.VK_CONTROL ||
                    vk == VirtualKeys.VK_LCONTROL ||
                    vk == VirtualKeys.VK_RCONTROL ||
                    vk == VirtualKeys.VK_MENU ||
                    vk == VirtualKeys.VK_LMENU ||
                    vk == VirtualKeys.VK_RMENU ||
                    vk == VirtualKeys.VK_LWIN ||
                    vk == VirtualKeys.VK_RWIN)
                {
                    bOutputVK = true;
                }

                if (ch != 0)
                {
                    if (bIsKeyDown)
                    {
                        sb.Append(ch);
                    }
                }
                else
                {
                    if (bIsKeyDown && sb.Length > 0)
                    {
                        lines.Add("\"" + sb.ToString() + "\"");
                        sb.Clear();
                    }

                    string vkStr     = vk.ToString();
                    string vkSendKey = ConstVariables.Vk2string(vkStr);

                    if (bOutputVK)
                    {
                        if (bIsKeyDown)
                        {
                            sb.Append("Keys." + vkSendKey + "+ \"");
                        }
                        else
                        {
                            lines.Add(sb.ToString() + "\" + Keys." + vkSendKey);
                            sb.Clear();
                        }
                    }
                    else
                    {
                        if (bIsKeyDown)
                        {
                            lines.Add("Keys." + vkSendKey);
                        }
                    }
                }
            }

            if (sb.Length > 0)
            {
                lines.Add("\"" + sb.ToString() + "\"");
            }

            return(lines);
        }
Ejemplo n.º 4
0
        public static List <string> GetDecodedKeyboardInput(string strBase64, bool bCapsLock, bool bNumLock, bool bScrollLock)
        {
            byte[] data = Convert.FromBase64String(strBase64);

            int  i     = 0;
            bool shift = false;

            StringBuilder sb    = new StringBuilder();
            List <string> lines = new List <string>();

            int nCtrlKeyDown = 0;

            while (i < data.Length / 2)
            {
                int n1 = i * 2;
                int n2 = i * 2 + 1;
                i++;

                bool        bIsKeyDown = data[n1] == 0;
                VirtualKeys vk         = (VirtualKeys)data[n2];

                char ch = ConstVariables.Vk2char((int)vk, shift || bCapsLock);

                if (bIsKeyDown) //Keydown
                {
                    if (char.IsControl(ch))
                    {
                        nCtrlKeyDown++;

                        if (nCtrlKeyDown == 1 && sb.Length > 0)
                        {
                            lines.Add("\"" + sb.ToString() + "\"");
                            sb.Clear();
                        }

                        string vkStr     = vk.ToString();
                        string vkSendKey = ConstVariables.Vk2string(vkStr);
                        if (nCtrlKeyDown == 1)
                        {
                            sb.Append("Keys." + vkSendKey);
                        }
                        else
                        {
                            sb.Append(" + Keys." + vkSendKey);
                        }
                    }
                    else if (ch != 0)
                    {
                        string strToAppend = ch.ToString();
                        if (ch == '\\')
                        {
                            strToAppend += "\\";
                        }

                        if (nCtrlKeyDown > 0)
                        {
                            sb.Append(" + \"" + strToAppend + "\"");
                        }
                        else
                        {
                            sb.Append(strToAppend);
                        }
                    }
                }
                else //Keyup
                {
                    if (char.IsControl(ch))
                    {
                        nCtrlKeyDown--;

                        string vkStr     = vk.ToString();
                        string vkSendKey = ConstVariables.Vk2string(vkStr);

                        if (nCtrlKeyDown == 0)
                        {
                            lines.Add(sb.ToString() + " + Keys." + vkSendKey);
                            sb.Clear();
                        }
                        else
                        {
                            sb.Append(" + Keys." + vkSendKey);
                        }
                    }
                }
            }

            if (sb.Length > 0)
            {
                lines.Add("\"" + sb.ToString() + "\"");
            }

            return(lines);
        }
Ejemplo n.º 5
0
        public string GetDescription()
        {
            if (_strDescription == null)
            {
                XmlDocument xmlDocument = new XmlDocument();
                try
                {
                    xmlDocument.LoadXml(_strXmlNode);
                }
                catch (Exception ex)
                {
                    return(ex.ToString());
                }

                XmlNodeList uiTasks = xmlDocument.GetElementsByTagName("UiTask");
                if (uiTasks.Count == 1)
                {
                    string strTask = uiTasks[0].Attributes["task"].Value;

                    _uiTaskName = ConstVariables.FromStringTaskName(strTask);

                    if (_uiTaskName == UiTaskName.KeyboardInput)
                    {
                        _strBase64Text = uiTasks[0].Attributes["base64String"].Value;

                        var varCapLock = uiTasks[0].Attributes["CapsLock"].Value;
                        if (varCapLock != null)
                        {
                            _bCapsLock = Convert.ToBoolean(varCapLock);
                        }

                        var varNumLock = uiTasks[0].Attributes["NumLock"].Value;
                        if (varNumLock != null)
                        {
                            _bNumLock = Convert.ToBoolean(varNumLock);
                        }

                        var varScrollLock = uiTasks[0].Attributes["ScrollLock"].Value;
                        if (varScrollLock != null)
                        {
                            _bScrollLock = Convert.ToBoolean(varScrollLock);
                        }

                        var           keyboardTaskDescription = GenerateCSCode.GetDecodedKeyboardInput(_strBase64Text, _bCapsLock, _bNumLock, _bScrollLock);
                        StringBuilder sb = new StringBuilder();
                        foreach (var strLine in keyboardTaskDescription)
                        {
                            sb.Append(strLine);
                        }

                        _strDescription = $"{_uiTaskName} VirtualKeys=\"{sb.ToString()}\" CapsLock={_bCapsLock} NumLock={_bNumLock} ScrollLock={_bScrollLock}";
                    }
                    else
                    {
                        var vleft = uiTasks[0].Attributes["x"];
                        _strLeft = vleft != null ? vleft.Value : "";

                        var vtop = uiTasks[0].Attributes["y"];
                        _strTop = vtop != null ? vtop.Value : "";

                        string name = uiTasks[0].LastChild.Attributes[ConstVariables.Name].Value;
                        if (string.IsNullOrEmpty(name))
                        {
                            name = uiTasks[0].LastChild.Attributes[ConstVariables.AutomationId].Value;
                            if (string.IsNullOrEmpty(name))
                            {
                                name = uiTasks[0].Name;
                            }
                        }

                        if (_uiTaskName == UiTaskName.Drag || _uiTaskName == UiTaskName.MouseWheel)
                        {
                            _strDescription = $"{_uiTaskName} on \"{name}\" at ({_strLeft},{_strTop}) drag ({_nDeltaX},{_nDeltaY})";
                        }
                        else
                        {
                            _strDescription = $"{_uiTaskName} on \"{name}\" at ({_strLeft},{_strTop})";
                        }
                    }
                }
            }

            return(_strDescription);
        }