Skip to content

Latest commit

 

History

History
20 lines (17 loc) · 466 Bytes

20040105-automatic-keyboard-focus.md

File metadata and controls

20 lines (17 loc) · 466 Bytes

Automatic keyboard focus

In response to an email I've got asking about forcing an applet to obtain the keyboard focus when it launches, here's a code snippet to do just this:

boolean needsFocus = true;

void loop() {
  // request focus from the system until received, but only do it once
  if (needsFocus) {
    if (!this.hasFocus()) {
      this.requestFocus();
    } else
      needsFocus = false;
  }
  // your normal code goes here...
  // ...
}