Skip to content

CTRL+V not posting 22 in P2D/P3D as it does in the default renderer #632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
processing-bot opened this issue Jan 6, 2023 · 7 comments
Labels
help wanted Extra attention is needed opengl

Comments

@processing-bot
Copy link
Collaborator

Created by: trackme518

Hi,
normally you can detect CTRL+V as a key==22 (ASCII) inside keyPressed(){} callback. However with P3D renderer this does not work. It also affects other combinations such as CTRL+Z and others.

Minimal code to reproduce the issue:

void setup() {
  //size(640, 480 ); //WORKS 
  size(640, 480, P3D); //DOES NOT WORK
}

int val = 0;

void draw() {
  background(val);
  val = 0;
}

void keyPressed() {
  if (key == 22 ) { //ASCII
    println("ctrl+v");
    val = 255;
  }
}
@processing-bot
Copy link
Collaborator Author

Created by: benfry

How about keyTyped()? That's two key presses, and depending on OS/renderer/etc it may be split out differently (ctrl-v is two separate key presses, but keyTyped() should give you the correct composite value).

@processing-bot
Copy link
Collaborator Author

Created by: trackme518

How about keyTyped()? That's two key presses, and depending on OS/renderer/etc it may be split out differently (ctrl-v is two separate key presses, but keyTyped() should give you the correct composite value).

Hi, I just tested that and it does not work either - it has something to do with the renderer as the default one work both with keyTyped() AND keyPressed() listeners but as soon as you use P2D or P3D it won't detect the combination. Also I am on Windows x64 platform.

@processing-bot
Copy link
Collaborator Author

Created by: benfry

Oh wait, I see you're using key but you should be checking keyCode, since it's not an actual char that's being typed. Doesn't that work?

@processing-bot
Copy link
Collaborator Author

Created by: trackme518

Oh wait, I see you're using key but you should be checking keyCode, since it's not an actual char that's being typed. Doesn't that work?

Hi,
it does NOT work. As I have already mentioned my original minimal code WORKS in default renderer - it would be strange that it require keyCode instead of key in P2D/P3D... Below you can test it on your own. As I have suggested there is a problem with P2D / P3D renderers and how they detect key presses, for example library Drop (used to drag and drop files on sketch) also works only in default renderer and not in P2D / P3D so maybe it has something in common (library: http://transfluxus.github.io/drop/ is listed in library manager....).

void setup() {
  size(640, 480 ); //WORKS
  //size(640, 480, P3D); //DOES NOT WORK
}

int val = 0;

void draw() {
  background(val);
  val = 0;
}

void keyPressed() {
  //if (key == CODED ) {
    //if (keyCode == 22 ) { does not work both in default renderer AND P2D/3D
    if (key == 22 ) { //WORKS in default renderer
      println("ctrl+v");
      val = 255;
    }
  //}
}

@processing-bot
Copy link
Collaborator Author

Created by: trackme518

I have also further tested the keyTyped() function. It does not work properly in P3D. In default renderer it works as expected. However in P3D the keyTyped() will detect NOTHING while the CONTROL key is pressed - in other words it will never detect the CONTROL key.

@processing-bot
Copy link
Collaborator Author

Created by: trackme518

Hi,
I think I have a solution. However it still bothers me it is inconsistent in different renderers. I have also tested on Windows x64 only so far so I have to verify on Mac as well. Below is the solution to detect CTRL+V in P3D renderer. You have to detect keyCode == 86 instead of key in P3D. In default renderer you just check for key==22

void setup() {
  //size(640, 480 ); //WORKS
  size(640, 480, P3D); //WORK BUT IN DIFFERENT WAY
}

int val = 0;

void draw() {
  background(val);
  val = 0;
}

void keyPressed() {
  println("key pressed: "+(int)key);
  println("keyCode pressed: "+ (int)keyCode);
  
  if (key == CODED) {
    if (keyCode == 86) {
      println("CTRL+V pressed in P3D renderer");
    }
  }
  
  //ctrl+v
  //in default renderer:--------
  //key pressed: 22

  //in P3D:----------------
  //keyCode pressed: 86
}

@processing-bot
Copy link
Collaborator Author

Created by: benfry

Yeah, that's a bug. The reason it's different is because the rendering surfaces all report key events differently, so we have a lot of extra code behind the scenes to make them work the same. Looks like ctrl-a through ctrl-z were just missed in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed opengl
Projects
None yet
Development

No branches or pull requests

1 participant