Ejemplo n.º 1
0
 public static extern int SendInput(int inputCount, INPUT[] inputs, int inputSize);
Ejemplo n.º 2
0
        public static void Type(string str, int pauserate)
        {
            foreach (char ch in str)
            {
                Thread.Sleep(pauserate);
                char typeCh = ch;
                IList<INPUT> inputList = new List<INPUT>();
                switch (ch)
                {
                    case ':':
                        {
                            typeCh = ';';
                            break;
                        }
                    case '<':
                        {
                            typeCh = ',';
                            break;
                        }
                    case '?':
                        {
                            typeCh = '/';
                            break;
                        }
                    case '~':
                        {
                            typeCh = '`';
                            break;
                        }
                    case '!':
                        {
                            typeCh = '1';
                            break;
                        }
                    case '@':
                        {
                            typeCh = '2';
                            break;
                        }
                    case '#':
                        {
                            typeCh = '3';
                            break;
                        }
                    case '$':
                        {
                            typeCh = '4';
                            break;
                        }
                    case '%':
                        {
                            typeCh = '5';
                            break;
                        }
                    case '^':
                        {
                            typeCh = '6';
                            break;
                        }
                    case '&':
                        {
                            typeCh = '7';
                            break;
                        }
                    case '*':
                        {
                            typeCh = '8';
                            break;
                        }
                    case '(':
                        {
                            typeCh = '9';
                            break;
                        }
                    case ')':
                        {
                            typeCh = '0';
                            break;
                        }
                    case '_':
                        {
                            typeCh = '-';
                            break;
                        }
                    case '+':
                        {
                            typeCh = '=';
                            break;
                        }
                    case '{':
                        {
                            typeCh = '[';
                            break;
                        }
                    case '}':
                        {
                            typeCh = ']';
                            break;
                        }
                    case '|':
                        {
                            typeCh = '\\';
                            break;
                        }
                    case '\"':
                        {
                            typeCh = '\'';
                            break;
                        }
                    default:
                        break;
                }
                byte vkCode = GetVirtualKeyCode(typeCh);
                ushort scanCode = 0;
                IntPtr extroInfo = IntPtr.Zero;
                if (vkCode == 0xff) //Input unicode
                {
                    vkCode = 0;
                    int character = typeCh;
                    scanCode = (ushort)character;

                    inputList.Add(ConstructINPUT(vkCode, scanCode, 4 | 0, extroInfo));
                    inputList.Add(ConstructINPUT(vkCode, scanCode, 4 | 2, extroInfo));
                }
                else
                {
                    if (ch == ':' || ch == '<' || ch == '>' || ch == '?' ||
                        ch == '~' || ch == '!' || ch == '@' || ch == '$' ||
                        ch == '%' || ch == '^' || ch == '&' || ch == '(' ||
                        ch == ')' || ch == '_' || ch == '+' || ch == '{' ||
                        ch == '}' || ch == '|' || ch == '\"' || ch == '#' || ch == '*' || isUpperCase(ch))
                        inputList.Add(ConstructINPUT((byte)VK.SHIFT, 0, 0, extroInfo));
                    inputList.Add(ConstructINPUT(vkCode, scanCode, 0, extroInfo));
                    inputList.Add(ConstructINPUT(vkCode, scanCode, 2, extroInfo));
                    if (ch == ':' || ch == '<' || ch == '>' || ch == '?' ||
                        ch == '~' || ch == '!' || ch == '@' || ch == '$' ||
                        ch == '%' || ch == '^' || ch == '&' || ch == '(' ||
                        ch == ')' || ch == '_' || ch == '+' || ch == '{' ||
                        ch == '}' || ch == '|' || ch == '\"' || ch == '#' || ch == '*' || isUpperCase(ch))
                        inputList.Add(ConstructINPUT((byte)VK.SHIFT, 0, 2, extroInfo));
                }
                INPUT[] inputs = new INPUT[inputList.Count];
                inputList.CopyTo(inputs, 0);

               SendInputs(inputs);
            }
            
        }
Ejemplo n.º 3
0
 private static void SendInput(INPUT input)
 {
     SUIWinAPIs.SendInput(1, new INPUT[] { input }, Marshal.SizeOf(input));
 }
Ejemplo n.º 4
0
 private static void SendInputs(INPUT[] inputs)
 {
     if(inputs != null && inputs.Length > 0)
     {
         SUIWinAPIs.SendInput(inputs.Length, inputs, Marshal.SizeOf(inputs[0]));
     }
 }
Ejemplo n.º 5
0
 private static INPUT ConstructINPUT(byte vk, ushort scan, int flags, IntPtr dwExtraInfo)
 {
     INPUT input = new INPUT();
     input.type = InputType.KEYBOARD;
     KEYBDINPUT kbInput = new KEYBDINPUT();
     kbInput.wVk = vk;
     kbInput.wScan = scan;
     kbInput.dwFlags = flags;
     kbInput.time = 0;
     kbInput.dwExtraInfo = dwExtraInfo;
     input.ki = kbInput;
     return input;
 }