Trigger key events

Does anyone know how to use the Windows API to simulate a keypress? i.e. in my code i call a function that causes an ‘a’ to register on the currently focused app.

1 Like

as usual i think i’ve figured it out now. but if anyone has any tips that’d be grand too :slight_smile:

As far as I know the only way would be to send the window a message containing a key press event…

I understand I'm in the wrong section but this post is relevant; I wanted to do this for Mac OS.

If I create a KeyPress, how do I actually trigger a message or send a "key press event" from JUCE?

Why are you trying to send a keypress event? What are you trying to achieve?

You could probably have a poke around in the Synergy source code to see how it's done:


This program seems to be able to 'inject' keyboard and mouse events on both OS X and Windows via some voodoo or other.

Hi Jules,

Sorry, I missed the notification for this message.
It wasn’t very critical anyway, so I kind of forgot about it.

I was building an application (for a college project) that classified percussive sounds, like kick/snare/hat, or beat-box, or finger snapping, etc. The idea here was to build a MIDI drum controller type application, but instead of a physical device, used audio cues, like tapping on a table to trigger MIDI events.

As part of my presentation for this application, I wanted to be a bit impressive and “go to the next slide of my presentation” with a snap of my finger, which would be triggered from the JUCE app running in the background. So I I was interested in figuring out how to send KeyPress events to the OS.

That presentation is done now so it doesn’t matter. But it would be pretty amazing if JUCE had a way to simulate HID events.