Trying to Register pressing ALT outside of the application window

Currently trying to make a over complicated software to run alongside other software and I’m currrently trying to get something to register colour changes in pixels while holding down a key. However, after trying to figure out why my idea wasn’t working after 2 hours of messing around, pressing keys aren’t registered while tabbed out of the application window.

Is there a way around it?