Click on button -> Type Keystroke

I am trying to set up a button so that when I click on it, the effect is that same as if I have made a keystroke on the keyboard.

For example, I click on a button and the effect is the same as if I had typed


Is this Possible with Xojo?

If you use MBS, it has a cross-platform PressKey as part of its RemoteControl plugin. On more recent macOS versions, that requires a system preference to be enabled. (But I forget which one – in Accessibility maybe?)

If all you care about is Windows, I think the Windows Functionality Suite had a declare at one point. I don’t use WFS so not sure if it is still current.


Yeah, search WFS for SendKeys. However, he said

Which means he probably is looking for macOS.

Yes, now that you mention it that seems true.

But also, if this is for your OWN app, I don’t recommend this approach at all. Move the code to a method that you call from both the button and a menu handler for the key or whatever.

VB’s SendKays() was never a good solution either, iMHO.

But if you are trying to send a keystroke to ANOTHER program, then sometimes your options are limited…

The WFS implementation doesn’t actually use SendKeys, that’s just what Aaron named it. The implementation is almost identical to how SendKeys was implemented, and it was meant to help VB devs make the jump. It actually uses the underlying API.

My point was simply that SendKeys() itself is not an ideal solution if you can avoid it – do web searches on VB forums for more context.

So if wanting to mimic a keystroke in one’s own program, I personally prefer encapsulating the ultimate logic in a method and calling from multiple places as needed.

Definitely not good to use for performing actions within your own program. I suppose I misunderstand what you were saying. Apologies!

The context is MacOS.

What I am trying to do is fire off a Keyboard Maestro script when that script is triggered by a Hot Key.

Does that app maybe offer to run scripts via command line or AppleScript?

Keyboard Maestro can use an AppleScript as a trigger. Since Xojo can launch an AppleScript, this is the methodology that I ultimately used.