0

I'm working on a little automation module for key presses and mouse-clicks, and while I've found the documentation for SendInput() and the Virtual Key Codes quite helpful for the standard keyboard and mouse input, I'm not sure how I can accomplish this task with the less ASCII-friendly potential input, like say, ®, or ê, which would be really helpful when trying to send localized strings to text fields.

I was thinking that using simulated key-presses was the way to go, but now I'm wondering if I should resort to some other sneaky devilry, like putting the string into the clipboard and doing a CTRL + V operation, or something like that and only sending virtual key-presses when appropriate.

My thought was doing something like this for all the specifically keyboard keys:

std::map<std::string,int> keys {
    {"0", 0x30},
    //...
    {"F24", 0x87}
};

Then iterating through each command line argument character-by-character to see if the whole arg only uses keys in the keys map in reference to the virtual key codes. If it does, just simulate the sequence of virtual keyboard key-codes with SendInput(). If it doesn't, I'm assuming it's not a valid direct key-press, and would do something like,

std::string to_send = argv[1];
pasteClipboard(to_send);

Is there a more straight-forward way to accomplish my goal? If not, any suggestions on how to implement a pasteClipboard style of method? I'm not using anything like Forms or MFC and would prefer to stick to the WINAPIs.

5
  • @BarmakShemirani I was thinking about seeing if any of the keys sent to the module in an arg weren't in the Virtual Key Codes with a maps key-check or something similar, and just handle pure virtual key code combos and text strings differently depending on the content of the argument that was passed in. Commented May 26, 2018 at 2:45
  • @IInspectable I'm actually using OpenCV's matchTemplate for locating GUI elements. That UI Automation thing seems nice, but for my requirements it seems like overkill. It's meant to roughly emulate what a BBT would be doing instead of programmatically handling controls and gathering data about it or events. Commented May 26, 2018 at 2:48
  • 1
    Trying to locate GUI elements based on image processing is way more involved and less reliable, than traversing the accessible tree, and having the GUI elements report their locations. Use the Inspect tool to see, what information UI Automation provides. What's more, UI Automation can access GUI elements, that aren't owned by the foreground thread, partially obscured by other windows, or completely invisible. Plus, it can cross UIPI boundaries, and isn't subject to the WDA_MONITOR display affinity of a window. Commented May 26, 2018 at 3:45
  • I'm sorry @IInspectable but maybe there was a misunderstanding. The intent of the module is to replicate what a BBT would be doing. As they locate things by-sight and use mice & keyboards, that's what this module is doing too. It doesn't even support what would be considered rudimentary gui automation support, like locating windows by name, and such. It's very stripped-down. Commented May 26, 2018 at 3:52
  • Virtual key codes cannot be distinguished from characters. They are all represent by bytes! If you must put everything in to one string then use something like this ideone.com/Vr2O7V - anyway, this question is getting too long. Commented May 26, 2018 at 19:55

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.