FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   detecting SHIFT / CTRL / Arrow keys?
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: detecting SHIFT / CTRL / Arrow keys?  (Read 960 times)
arielm

WWW
detecting SHIFT / CTRL / Arrow keys?
« on: Apr 25th, 2003, 5:40pm »

on my p5 0054 / win2k / JRE1.4.x, the "key" variable is returning 65535 when i press SHIFT, CTRL or one of the arrow keys...
 
but i badly need to detect them!
 
doctor, is it normal? is there a cure to this?
 

Ariel Malka | www.chronotext.org
pollux

WWW Email
Re: detecting SHIFT / CTRL / Arrow keys?
« Reply #1 on: Apr 25th, 2003, 8:48pm »

saddling P5 0054 / WINMX / JRE1.4.1x, i discovered them with this code:
 
Code:

public void keyPressed(KeyEvent e) {  
  println(e); // shows whole info on the pressed key
  println(e.getKeyCode()); // shows keyCode
  int myKey = e.getKeyCode();
  if (myKey == 10) {
    ... code ...
  }
}

 
btw, it gives me:
 
LEFT = 37;  
RIGHT = 39;  
UP = 38;  
DOWN = 40;
CTRL = 17;  
ALT = 18;  
SHIFT = 32;
 
NOTE: since it catches the key being pressed, if you use switch, don't forget to add a break; after the action, if not, it continues catching it ad infinitum...
« Last Edit: Apr 25th, 2003, 8:51pm by pollux »  

pollux | www.frwrd.net
arielm

WWW
Re: detecting SHIFT / CTRL / Arrow keys?
« Reply #2 on: Apr 25th, 2003, 10:37pm »

10-x! it works perfectly...
 

Ariel Malka | www.chronotext.org
toxi

WWW
Re: detecting SHIFT / CTRL / Arrow keys?
« Reply #3 on: Apr 29th, 2003, 12:21pm »

alternatively, you can also get the name of the key pressed via:
 
public void keyPressed(KeyEvent e) {
  println(e.getKeyText(e.getKeyCode()) );
}
 
if you want to find out, if shift/control/alt is still pressed in conjunction with another key, use these methods of the KeyEvent (all return true/false):
 
e.isShiftDown()
e.isControlDown()
e.isAltDown()
 

http://toxi.co.uk/
REAS


WWW
Re: detecting SHIFT / CTRL / Arrow keys?
« Reply #4 on: Apr 29th, 2003, 8:18pm »

We are adding a variable called "keyCode" which will make it easy to trap for special keys.
 
fry


WWW
Re: detecting SHIFT / CTRL / Arrow keys?
« Reply #5 on: Jun 25th, 2003, 8:43pm »

this has been implemented for 0056 for UP, DOWN, LEFT, RIGHT, ALT, CONTROL, and SHIFT.
 
Code:
void keyPressed()  
{
  if (key == UP) {
    println("up");
 
  } else if (key == DOWN) {
    println("down") {
 
  } else {
    println("around");
  }
}
 
Pages: 1 

« Previous topic | Next topic »