Listening to events while Processing window is inactive

Hey guys, new here and relatively new to programming. I have been asked to create a small program for a friends. A program that monitors activities on the keyboard and mouse. I have however run into a problem with processing, and have search wide and far for a solution.

The problem seems to be, that as soon as the window is not in focus, even when forced to be in the front layer of the screen, the “keyPressed()” and “mousePressed()” listeners stop taking input. This defeats the purpose of the intended program.

I did find some old posts on the old Processing Forum regarding this problem, and I seemed almost impossible to make it work. Has there been any updates to this problem or is it simply impossible for processing to work in this manner with the windows operating system?

Thanks regardless!

This issue is not just with Processing its the same for all applications and all multitasking operating systems, at least with the ones I have used, Windows and Osx.

Although a multitasking OS supports several applications being open at the same time only one of these applications can be active at any moment in time.

The OS detects the mouse and keyboard events and forwards them to the active application only so your sketch will only get the results if it is the active application.


You will have to use libraries that support keyboard monitoring. In Python, I know something like pynput works. Searching online I find this Stackoverflow post, and maybe something like JNativeHook would work. (I have not looked at it, not having experience in Java)

1 Like

Yeah, that is what I figured. I have however seen other applications receiving input or at least tracking this input from the OS somehow. I was wondering if Processing had a library or built in tool for this. But thanks for the answer! :slight_smile:

Cool, so Python has a way of achieving this. I think I will look into some python then. Thanks!

1 Like