Leonardo keypresses not working with OBS
Warning: the below is all supposition.
When the OBS window is focused the OS can send keyboard events to the window. That means that it gets &quot;The button has been pressed&quot; messages. These are generated when the &quot;press&quot; events are sent from the Leonardo.
When the OBS window isn't focused it can't be sent those messages - so it has to manually poll the state of the keyboard to see what buttons are pressed at any one time. It can't be doing this all the time, so it does it periodically (but still pretty fast).
The knock-on effect is, though, that when not focused it can only see buttons that have been pressed for at least enough time for it to poll the state.
If you add a delay into your routine between the last &quot;press&quot; and the &quot;release all&quot; commands that is longer than the period between polling (no idea what that is - you'll have to experiment, but starting at around 50ms to 100ms should be adequate) you should give OBS enough time to see that the buttons are pressed before you then release them.