Skip to content

Caps Lock ignored by P3D renderer #5824

@mcslee

Description

@mcslee

Description

JAVA2D respects CAPS LOCK - when the keyPressed callback is invoked, the key value will be uppercase if caps-lock is on.

However, when using P2D/P3D, caps lock is ignored. The key value is lowercase even when CAPS LOCK is on.

Expected Behavior

The value of key should respect the state of caps-lock on the keyboard. Or probably at least be consistent between P2D/P3D/JAVA2D renderers.

Current Behavior

The P2D/P3D renderer ignore caps lock. No events fired for caps lock keys and key values are always lowercase.

The default JAVA2D renderer respects case, and additionally fires a keyPressed/keyReleased event for the toggling of caps lock, with java.awt.event.KeyEvent.MAX_VALUE as the key).

Steps to Reproduce

Use the program below. Switch JAVA2D to P2D and then to P3D. In each case:

  1. Type some characters, see what is logged
  2. Turn CAPS LOCK on, type characters, see what is logged
  3. Turn CAPS LOCK on and off, see if events are fired for caps lock key itself
void setup() {
  size(100, 100, JAVA2D);
}
void draw() {}
void keyPressed() {
  println("Pressed: " + key + " " + (int) key);
}
void keyReleased() {
  println("Released: " + key + " " + (int) key);
}

Your Environment

  • Processing version: 3.5.3
  • Operating System and OS version: macOS 10.14.3

Possible Causes / Solutions

One way to fix this for P3D would be to modify the nativeKeyEvent method in PSurfaceJOGL.
https://github.com/processing/processing/blob/master/core/src/processing/opengl/PSurfaceJOGL.java#L1079

A call could be made to:
Toolkit.getDefaultToolkit().getLockingKeyState(java.awt.event.KeyEvent.VK_CAPS_LOCK)
https://docs.oracle.com/javase/8/docs/api/java/awt/Toolkit.html#getLockingKeyState-int-

If true, key could be replaced by Character.toUpperCase(char)

This ought to work, but may be undesirable to mix AWT Toolkit code with JOGAMP NEWT input handling. I looked at the NEWT docs but didn't see an obvious way to get caps-lock state out of there.

Bug was discovered by @jkbelcher

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions