Skip to content

SHIFT and PAGE_UP keys use the same keyCode in P2D and P3D #702

Open
@processing-bot

Description

@processing-bot
Collaborator

Created by: slu4coder

Hi guys,

thanks for your excellent work on Processing 4. Sorry to report this annoying issue making it essentially impossible to detect the difference between SHIFT and PAGE_UP when using the P2D renderer. Problem: Both use keyCode = 16 :-(

This is not a problem under the DEFAULT renderer. It uses keyCodes 33-35 for HOME/END/PG_UP/PG_DN and 16 for SHIFT.
P2D however uses keyCodes 2, 3, 16(?) and 11 for the above keys and again 16 for SHIFT.

Btw, I am typing on a German keyboard but for the keys involved that shouldn't make any difference, I guess.

Good luck! slu4.

void setup() { size(200, 200, P2D); }
void draw() {}
void keyPressed() { println(key, int(key), key==CODED, keyCode); }

Activity

processing-bot

processing-bot commented on Jun 20, 2023

@processing-bot
CollaboratorAuthor

Created by: Chirimen-Jako

I was also trying to submit the exact same issue, but I'm adding it here since I found this report. I am using the P3D renderer and a Japanese keyboard. Like slu4coder, I cannot distinguish between the [Shift] key and the [Page Up] key because they both return the same keyCode 16.

Additionally, I would like to ask if this issue is dependent on the hardware type of the keyboard.

// Processing 4.2 on Windows 10 22H2 build 19045.3086
void setup(){
  size(320, 240, P3D);
  background(255);
}
void keyPressed(){
  // [Shift] returns '16 0x10'
  // [Page Up] returns '16 0x10'
  int kc = keyCode;
  println(kc + " 0x" + hex(kc, 2));
}
void draw(){}
processing-bot

processing-bot commented on Jun 21, 2023

@processing-bot
CollaboratorAuthor

Created by: Chirimen-Jako

I found a workaround.

// Processing 4.2 on Windows 10 22H2 build 19045.3086
void setup(){ size(320, 240, P3D); }
void draw(){}
void keyPressed(KeyEvent e){

  // Default renderer
  //java.awt.event.KeyEvent nativeEvent = (java.awt.event.KeyEvent)e.getNative();

  // P2D/P3D renderer
  com.jogamp.newt.event.KeyEvent nativeEvent = (com.jogamp.newt.event.KeyEvent)e.getNative();

  int kcd = keyCode; // default
  int kcn = nativeEvent.getKeyCode(); // native

  // renderer:default
  // keyCode   :  default   native         
  // [Shift]   :  16 0x10 / 16 0x10
  // [Page Up] :  33 0x21 / 33 0x21

  // renderer:P2D/P3D
  // keyCode   :  default   native         
  // [Shift]   :  16 0x10 / 15 0x0F
  // [Page Up] :  16 0x10 / 16 0x10

  println(kcd, "0x" + hex(kcd, 2), "/", kcn, "0x" + hex(kcn, 2));
}
processing-bot

processing-bot commented on Jul 16, 2023

@processing-bot
CollaboratorAuthor

Created by: benfry

Ok, these should be getting mapped properly to the same values as in the Java2D renderer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @processing-bot

      Issue actions

        `SHIFT` and `PAGE_UP` keys use the same `keyCode` in `P2D` and `P3D` · Issue #702 · processing/processing4