# Listening to events while Processing window is inactive

**URL:** <https://discourse.processing.org/t/listening-to-events-while-processing-window-is-inactive/38022>\
**Category:** Project Guidance\
**Tags:** homework\
**Created:** [July 19, 2022, 3:55am UTC](https://discourse.processing.org/t/listening-to-events-while-processing-window-is-inactive/38022 "2022-07-19T03:55:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BetaHunter](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/betahunter/32/20758_2.png) [@BetaHunter](https://discourse.processing.org/u/BetaHunter)\
**Post date:** [July 19, 2022, 3:55am UTC](https://discourse.processing.org/t/listening-to-events-while-processing-window-is-inactive/38022/1 "2022-07-19T03:55:01Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [July 19, 2022, 9:47am UTC](https://discourse.processing.org/t/listening-to-events-while-processing-window-is-inactive/38022/2 "2022-07-19T09:47:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ckyiu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ckyiu/32/16154_2.png) [@Ckyiu](https://discourse.processing.org/u/Ckyiu)\
**Post date:** [July 19, 2022, 1:24pm UTC](https://discourse.processing.org/t/listening-to-events-while-processing-window-is-inactive/38022/3 "2022-07-19T13:24:13Z")

</div>

You will have to use libraries that support keyboard monitoring. In Python, I know something like [`pynput`](https://pypi.org/project/pynput/) works. Searching online I find [this](https://stackoverflow.com/q/2168968/10291933) Stackoverflow post, and maybe something like [`JNativeHook`](https://github.com/kwhat/jnativehook) would work. (I have not looked at it, not having experience in Java)

---

<div class="post-metadata">

**Author:** ![BetaHunter](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/betahunter/32/20758_2.png) [@BetaHunter](https://discourse.processing.org/u/BetaHunter)\
**Post date:** [July 19, 2022, 8:06pm UTC](https://discourse.processing.org/t/listening-to-events-while-processing-window-is-inactive/38022/4 "2022-07-19T20:06:22Z")

</div>

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! 🙂

---

<div class="post-metadata">

**Author:** ![BetaHunter](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/betahunter/32/20758_2.png) [@BetaHunter](https://discourse.processing.org/u/BetaHunter)\
**Post date:** [July 19, 2022, 8:07pm UTC](https://discourse.processing.org/t/listening-to-events-while-processing-window-is-inactive/38022/5 "2022-07-19T20:07:27Z")

</div>

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