2

I'm trying to automate the insertion of some data in a software. This software has a popup window that require a password with a textfield and 2 button.

My intent is to write that password and press ENTER on that field with a powershell script.

I've tried many methods, like Windows.Form.SendKeys, but none of that write in that field. I've even tried the InputSimulator class, but even that cannot write in that field. The only thing I've tried that can write to that field is the On Screen Keyboard of window. After some search I've found that it should use the SendInput command to simulate the key. Using Api Monitoring I've checked the call, and I've recreated a similar SendInput call to write a lowercase 'a', using a code similar to the one in this answer: https://stackoverflow.com/a/18854441/4417646

I've tried with and without the wVk value, but my script still cannot write in that field. I've monitored all the other call regarding the keyboard that is done form the onscreen keyboard, but I haven't seen any. Before send the SendInput command, I use a code to focus the window and 1 second of sleep to be sure that the form is on focus. If I use the same call with any other window, it work... (I've tried with notepad and other random software)

Am I missing something?

Here's the part of code that call SendInput: (it's a c# class exported to powershell)

public static void SendKeyboard(char ch) {
    lpInput[] KeyInputs = new lpInput[1];
    lpInput KeyInput = new lpInput();
    // Generic Keyboard Event
    KeyInput.type = InputType.INPUT_KEYBOARD;
    KeyInput.Data.ki.time = 0;
    KeyInput.Data.ki.dwExtraInfo = UIntPtr.Zero;

    short key = VkKeyScan(ch);
    uint mappedKey = MapVirtualKey( LoByte( key ), 0 );

    // Push the correct key
    KeyInput.Data.ki.wVk = 0;
    KeyInput.Data.ki.wScan = (Int16)mappedKey;
    KeyInput.Data.ki.dwFlags = KEYEVENTF.SCANCODE;
    KeyInputs[0] = KeyInput;
    SendInput(1, KeyInputs, lpInput.Size);

    // Release the key
    KeyInput.Data.ki.dwFlags = KEYEVENTF.SCANCODE | KEYEVENTF.KEYUP;
    KeyInputs[0] = KeyInput;
    SendInput(1, KeyInputs, lpInput.Size);

    return;
}

Thanks to everyone! I Hope someone can help me ;)

Community
  • 1
  • 1
Mix Kira
  • 107
  • 1
  • 8

0 Answers0