We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Input from keyboard of special characters
Page Index Toggle Pages: 1
Input from keyboard of special characters (Read 1914 times)
Input from keyboard of special characters
Aug 18th, 2005, 9:57am
 
I'm wondering how to identify the input of characters that required particular combinations to be typed, like "{","}","[" and "]" that in my keyboard has to be insert using CTRL + key or CTRL + SHIFT + key. It seems that the "key" in the code is not found and if I print it, it is "?". Is there any limitation on the characters I can type from the keyboard?

thx, chr
Re: Input from keyboard of special characters
Reply #1 - Aug 18th, 2005, 10:07am
 
I don't know if it works but have you tried the unicode character equivalent. i.e fullstop (or period) = \u002e

*** Update ***

This works for me:

Code:


if(key == '\u002e') {

// stuff to do.

}

Re: Input from keyboard of special characters
Reply #2 - Aug 18th, 2005, 1:46pm
 
it seems the problem is with my italian keyboard that to type some not very common characters has to make those odd combos. On the english keyboard for almost all the characters there is not so much problem. I'll test later the unicode option but I think the problem is of a different nature.

Thanks, chr
Re: Input from keyboard of special characters
Reply #3 - Aug 18th, 2005, 4:53pm
 
nah, that sort of thing should work just fine. java/p5 are built to deal with international characters/keyboards properly.

the ? is that the key is "coded" key:
http://processing.org/reference/keyCode.html
and the value will be in keyCode. there are constants for many of the keys in processing, the rest can be found in the full java documentation about how KeyEvent works:
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/event/KeyEvent.html

see also the developer reference for keyPressed()
http://dev.processing.org/reference/core/javadoc/processing/core/PApplet.html#keyPressed()
which explains more of how this works in processing.
Re: Input from keyboard of special characters
Reply #4 - Aug 19th, 2005, 12:06am
 
well, if I use this simple code:
Code:
void keyPressed()
{
if(key == CODED){
println(keyEvent);

And I type Alt GR + key ("[" for the italian keyboard) I get:

java.awt.event.KeyEvent[KEY_PRESSED,keyCode=18,keyText=Alt,keyChar=Undefined keyChar,modifiers=Ctrl+Alt,extModifiers=Ctrl+Alt,keyLocation=KEY_LOCATION_RIGHT]
on panel0

So it doesn't seem so helpful Sad
Am I missing something?


Thanks, chr
Re: Input from keyboard of special characters
Reply #5 - Aug 19th, 2005, 6:38am
 
what character should that keypress make? is there a VK_XXXXX constant in the KeyEvent reference for the character that it should produce? i.e. if it were just a left bracket, then you'd want something like:

if ((key == CODED) && (keyCode == KeyEvent.VK_OPEN_BRACKET))
Re: Input from keyboard of special characters
Reply #6 - Aug 19th, 2005, 9:46am
 
thanks fry for the patience but with this code:


Code:
   if (key == CODED){
println(KeyEvent.getKeyText(keyCode));
if(keyCode == KeyEvent.VK_CLOSE_BRACKET){
println("CLOSE BRACKET");
}
}


pressing some combo keys I got just:

Ctrl
Alt

with others:

Ctrl
Alt
Unknown keyCode: 0x0

And of course there is no way to type the closing brackets and I never get in that if.

Any other ideas? Smiley


Thanks a lot man, chr
Re: Input from keyboard of special characters
Reply #7 - Aug 19th, 2005, 4:18pm
 
did you read the link from the developer reference? a keyPressed() will be called when alt or ctrl is hit, followed by another when you hit any other keys as part of a ctrl- or alt- combo. you might want to be using keyTyped(), for instance, which should only fire with the "final" key stroke.
Re: Input from keyboard of special characters
Reply #8 - Aug 19th, 2005, 4:46pm
 
I looked the javadoc but also for your anchor I didn't get to the events :S. Actually I had to read better http://java.sun.com/j2se/1.4.2/docs/api/java/awt/event/KeyEvent.html#KEY_TYPED (what a stupid man I am)
Anyway, u r right, at the end what I needed is just to get the typed chars and keyTyped seems to work perfectly!

And why inside this last event the key is always not CODED?

Many thanks, chr
Re: Input from keyboard of special characters
Reply #9 - Aug 19th, 2005, 5:16pm
 
you have to copy and paste the url from my post, because yabb doesn't handle the parens () at the end of the url properly. or go to that page and scroll down to the key event ref.
Re: Input from keyboard of special characters
Reply #10 - Aug 19th, 2005, 5:50pm
 
no, it worked. It is that it brought me to the right method but I had to find the detail at the bottom of the page (another anchor for the detail version in the javadoc would have helped Smiley )

thx, chr
Re: Input from keyboard of special characters
Reply #11 - Aug 19th, 2005, 6:15pm
 
if you copy and paste it properly, it *is* the detailed explanation in the javadoc.
Re: Input from keyboard of special characters
Reply #12 - Aug 19th, 2005, 7:46pm
 
finally I got what you meant Smiley I didn't expected the "()" as part of the anchor Smiley

thx, chr
Page Index Toggle Pages: 1