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);
        }
Exemple #2
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);
        }