Register a key press while working outside the sketch window?

I’m currently working on a program to assist me in a game but I’d like to add a few other controlls including when to shut the program down.

However the keyPressed method only is called when the window is currently activated. So when I play the game I can’t input controlls into my program.

Without knowing more about your problem, here are some guesses:

Do you specifically want a hotkey that quits Processing? You could try using a hotkey / shortcut program for your operating system of choice (Windows? Mac? Linux?) to do this.

For example, on macOS I believe that Alfred has a kill app option. So you could be in a full screen game, pull up Alfred with the hotkey, and kill Processing.

Another alternative if you want to signal your Processing program itself from elsewhere might be to use OSC. Then you could use e.g. a USB MIDI controller / keypad / keyboard mapping which is signaling the Processing sketch, whether or not it has focus.