Processing 3 and right/left shift

November 16th, 2020

In Processing 2 it was relatively easy to tell the difference between the right and left shift by overriding keyPressed(java.awt.event.KeyEvent ke), but in Processing 3 event handling has changed and the function doesn’t even get called any more. I really really wanted to use the two keys differently and came up with this blurb for the keyPressed() handler:

if(keyCode==SHIFT)
{
  java.awt.event.KeyEvent ke;
  ke=(java.awt.event.KeyEvent)keyEvent.getNative();

  if(ke.getKeyLocation()==KeyEvent.KEY_LOCATION_LEFT)
  {
    // It's the left shift
  }
}

Note that this will only work with the default renderer, as the others don’t use AWT. The “solution” is also deprecated, so it might stop working any time and then we need another hack to work around the issue. Things would be so much easier if Processing simply provided a different keyCode for the two keys, but I wouldn’t hold my breath waiting for that.

Filed under: koodi,softat

Kommentin kirjoitus

You must be logged in to post a comment.

RSS feed for comments on this post.


Kommenttien virta

Aiheet