I am using an Arduino Leonardo to have hotkeys for OBS but they don't work when the OBS Studio window is not focused.

I have the Leonardo press Ctrl + Alt + Shift + F7 when I press a button connected to the Leonardo. On OBS I have Ctrl + Alt + Shift + F7 switch to a slide. When I have the OBS window focused and I press the button it works fine. But when I have another application focused it does not work. The strange thing is, is that when I press (on my keyboard) Ctrl + Alt + Shift + F7, it will switch to the slide, but when I press the button it does not work.

I am running OBS as an Administrator btw.

My code for the Leonardo is below

int pinA = 8;

void setup() {
    pinMode(pinA, INPUT);

void loop(){
digitalWrite(pinA, HIGH);
readPinA = digitalRead(pinA);
if (readPinA == 0){
  • you really need to examine the example sketch closely
    – jsotola
    Commented Aug 31, 2020 at 21:12
  • @jsotola could you give me a bit more info?
    – Ryan Vogel
    Commented Aug 31, 2020 at 21:18
  • Try adding a delay between pressing the keys and releasing them all.
    – Majenko
    Commented Aug 31, 2020 at 21:42
  • @RyanVogel have you looked at the example sketch? ... what does it have that your sketch does not have?
    – jsotola
    Commented Aug 31, 2020 at 22:29

1 Answer 1


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 "The button has been pressed" messages. These are generated when the "press" 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 "press" and the "release all" 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.

  • This worked! Thanks!
    – Ryan Vogel
    Commented Sep 2, 2020 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.