Test whether a button has been pressed even when the program is minimized

Hi I want to create a program that runs in the background and tests whether a key has been pressed. Like a keylogger…
I need that because when I press ALT & S, for example, I want to take a screenshot.

Here is the Code that I have for the Screenshot:

import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.awt.Rectangle;

Robot robot;

PImage screenImage;

PVector a, b;
PVector c, s;

void setup() {
  fullScreen();
  setRobot();
  screenImage = captureScreen();
  a = new PVector(0, 0);
  b = new PVector(0, 0);
  c = new PVector(0, 0);
  s = new PVector(0, 0);
}
void draw() {
  background(255, 0, 0);
  image(screenImage, 0, 0);
  if (mousePressed) {
    b.set(mouseX, mouseY);
    setCenterAndSize();

    fill(255, 0, 0, 60);
    stroke(255, 0, 0);
    rectMode(CENTER);
    rect(c.x, c.y, s.x, s.y);
  }
}
void mousePressed() {
  a.set(mouseX, mouseY);
  b.set(mouseX, mouseY);
}
void mouseReleased() {
  setCenterAndSize();
  selectOutput("Where should the screen be saved?", "fileSelected");
}
void fileSelected(File selection) {
  PImage si = screenImage.get(abs(int(c.x+s.x/2)), abs(int(c.y+s.y/2)), abs((int)s.x), abs((int)s.y));
  si.save(selection.getAbsolutePath());
  exit();
}
void setCenterAndSize() {
  float x = (a.x+b.x)/2;
  float y = (a.y+b.y)/2;
  c.set(x, y);
  s.set(min(a.x, b.x)-max(a.x, b.x), min(a.y, b.y)-max(a.y, b.y));
}
void setRobot() {
  try {
    robot = new Robot();
  }
  catch(Exception e) {
    println(e.getMessage());
  }
}
PImage captureScreen() {
  surface.setVisible(false);
  Rectangle rect = new Rectangle(0, 0, displayWidth, displayHeight);
  BufferedImage bufferedImg = robot.createScreenCapture(rect);
  surface.setVisible(true);
  PImage i = new PImage(bufferedImg);
  return i;
}

In processing you can use surface.setVisible (false); to make the program invisible. But as soon as this happens, the keyPressed function is no longer executed…
I hope you can help me :smile: