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 have been using Leonardo in many of my projects and like this controller because of the capability to "act" like keyboard or mouse. But sometimes it is "tricky" to get the results you need.
The code you posted does not compile because of missing (at least):
#include "Keyboard.h"
at the top of the sketch
and
Keyboard.begin();
in setup.
Depending on the operating system (and other things) you may get different results using left or right modifier keys.
For example on my current computer (Windows 10) the following line does not work (ALT key will not be recognized):
Keyboard.press(KEY_RIGHT_ALT);
But this line will work (ALT key will be recognized):
Keyboard.press(KEY_LEFT_ALT);
(I am not sure if this behavior has to do with the fact that on my "real" keyboard there is no right ALT key at all but an ALT GR key. I did not check if this behavior has to do with the specific software currently running).
My experience is that some machines don't "like" too short key presses, witch may be produced by using
Keyboard.press(....) and Keyboard.release()
without any delay between.
See also this topic: OBS - Solved: Global Hotkeys
On my current computer there is no OBS (but I know this software), so I can not test the code below with OBS. But with all said above a modification of your code could look like this (the push button is connected to pin 8 and GND):
sterretje:
But I find it strange that the normal keyboad actually can change the focus to a specific program using .
Global Hotkeys are shortcuts you can use even if an application does not have the focus.
Commonly used for example with well known "player applications" like VLC or AIMP.
uxomm: Global Hotkeys are shortcuts you can use even if an application does not have the focus.
Commonly used for example with well known "player applications" like VLC or AIMP.
Never heard of them; thanks for pointing it out. karma added.