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.
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.