Programmatically generate keystroke

Is it possible to generate a keystroke programmatically that will be recognized by the UI of the app? In particular I want to generate a tab character in order to move to the second subfield of a UI widget.

In general I prefer to avoid generating keystrokes unless there is no alternative. If the intent is to manipulate the UI of your own app, please consider other methods instead such as using .SetFocus or whatever.

But to more directly answer your question, one of things will be cross-platform compatibility and another will be OS restrictions. Under macOS for example, the user must have authorized the app to “control the computer” (i.e. System Preferences > Security & Privacy > Automation).

If you have MBS, see also RemoteControlMBS for one way to do it.

If you only care about Windows, there may be something in the old Windows Functionality Suite which mimics VB’s “SendKeys” behavior. I have not checked; and even if there is, I don’t know if it is oudated.

But for controlling focus of your own app, I suggest you do it with .SetFocus or similar instead of trying to inject tab keystrokes.

1 Like

Unfortunately this is a plugin with several UI subfields. It defaults to selecting the first subfield, and there isn’t a way to move to the second subfield apart from physically pressing the tab key or clicking with the mouse on that subfield. I have asked the plugin developer if there’s a solution. I will try RemoteControlMBS - it looks promising, thanks.

1 Like

I use RemoteControlMBS in a couple of my apps. Works perfectly.

1 Like