Checking active application realtime

I am a webdeveloper and have multiple programs which i need to "debug". For example Safari (javascript), but also VSCode etc.

All these programs use different keys to pause, step in, step over etc. I would like to build my own small keyboard (via an arduino for example) and use a few keys to simulate those keys.

What i need to know is which program is active, is it possible to make a "background" program for my mac which detects if the focus is on Safari, VSCode etc so if i press a key via the arduino, i can send different keycodes to the Mac?

I assume it is not possible?

Checking active application realtime
 
 
Q