code: void setState(KeyState newState) {
          if (MonocleSettings.settings.traceEvents) {
              MonocleTrace.traceEvent("Set %s", newState);
          }
          newState.getWindow(true);
          // send release events
          state.getKeysPressed().difference(keys, newState.getKeysPressed());
          if (!keys.isEmpty()) {
              for (int i = 0; i < keys.size(); i++) {
                  int key = keys.get(i);
                  dispatchKeyEvent(newState, KeyEvent.RELEASE, key);
              }
          }
          keys.clear();
          // send press events
          newState.getKeysPressed().difference(keys, state.getKeysPressed());
          if (!keys.isEmpty()) {
              for (int i = 0; i < keys.size(); i++) {
                  int key = keys.get(i);
                  if (key == KeyEvent.VK_CAPS_LOCK) {
                      capsLock = !capsLock;
                  } else if (key == KeyEvent.VK_NUM_LOCK) {
                      numLock = !numLock;
                  } else if (key == KeyEvent.VK_C && newState.isControlPressed()) {
                      AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
                          if ("1".equals(System.getenv("JAVAFX_DEBUG"))) {
                              System.exit(0);
                          }
                          return null;
                      });
                  }
                  dispatchKeyEvent(newState, KeyEvent.PRESS, key);
              }
          }
          keys.clear();
          newState.copyTo(state);
      }
docs: Called from the input processor to update the key state and send
  key events.
  
  @param newState The updated key state