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 › external keyboard
Page Index Toggle Pages: 1
external keyboard (Read 588 times)
external keyboard
Jul 9th, 2009, 12:31pm
 
i've pluged in an external keyboard to my laptop. when opening my processing sketch and typing with my laptop keyboard everythings works fine. when using my external keyboard the sketch does not work.....the numbers are not displayed correctly instead there are shown fragments....
this is the sketch i use:

Code:
PFont font;
int i;
void setup() {
size (1000,1000);
font = createFont ("Lucida Sans Typewriter",50);
 textFont (font);
}
 void draw(){}
 
 void keyReleased() {
   i+=50;
  text(key,i,100);
   
 }

thats what the code looks like when using the laptop keyboard (first three numbers) and the external keyboard (the last three numbers)
http://www.pic-upload.de/view-2521743/Bild-5.png.html

does anyone has an idea what the problem might be?
when using the external keyboard inside the web browser or microsoft word it works perfectly well. just inside processing it struggles.
i also tried a different font....
Re: external keyboard
Reply #1 - Jul 9th, 2009, 1:21pm
 
No problems here and I'm using a USB keyboard connected to my laptop.  If I've understood correctly each time you press a number on your external keyboard you get get "[]1[]"?

I might hazard a guess that to enter a number for some reason it's switching NumLock on and off.  Try adding:

if (key == CODED) {
    println(keyCode);
}

to your keyReleased code - that will give you the code of the extra characters being submitted.  You might just have to add a condition to exclude them when using your keyboard.
Re: external keyboard
Reply #2 - Jul 9th, 2009, 2:45pm
 
it becomes even more strange...when using if (key == coded) etc. and using it with my laptop keyboard it does not print out anything. using my external number pad i only get printed out "12" no matter what i type in........
Re: external keyboard
Reply #3 - Jul 9th, 2009, 9:06pm
 
ok i know what went  wrong.
each time i press a key it sets first the keyCode 144 then e.g. 12 and then again 144.
now, when using my keyboard i have this function:

function keyTyping () {
text (key, PosY,PosY);
}

You might just have to add a condition to exclude them when using your keyboard.
so how can i exclude the 144-keyCode character without deleting the others key presses?
note: i just use a number pad, that makes it even more strange....
so when typing a "1" i get the keyCode 49. now when using my external keyboard i get "144""49"144". is there a skip function or something that can ignore the 144 and only hint for the other keyCodes???

hope you can help me, this would be great!!!


Re: external keyboard
Reply #4 - Jul 10th, 2009, 12:17am
 
Well sounds like my hunch was correct - 144 is what I get from numLock on my external keyboard too.  Why it has to invoke it each time you press a number I don't know, though I'm guessing it's a German keyboard which may have to handle extra characters and this is how they've dealt with it.

As for the condition... Can't you just:

function keyTyping () {
 if(keyCode !=144){
   text (key, PosY,PosY);
 }
}
Re: external keyboard
Reply #5 - Jul 10th, 2009, 1:06am
 
i thought so too.but it does not change anything.
when using this code with my external keybooard and printing out the keyCode it still prints out "144" the pressed nummber and again "144".
indeed it's a german keyboard. but it worked once and now i can't get it running again. still the same mistake....
any other idea how to get rid of this??? i thought of an external programm to deactivate the numlock key....does not work either
Re: external keyboard
Reply #6 - Jul 10th, 2009, 1:24am
 
Actually that kind of makes sense since it's a keyReleased function - presumably all three characters are passed in unison on keyReleased.  In which case I guess you may have to parse it somehow; though TBH it seems to me that this is a problem with the setup of your keyboard so you would be fixing it for a very tiny minority of users.  Maybe you just need to re-install the drivers for the keyboard or change a setting somewhere?
Re: external keyboard
Reply #7 - Jul 10th, 2009, 3:24am
 
i got it

PFont font;
int i;
void setup() {
size (1000,1000);
font = createFont ("Lucida Sans Typewriter",50);
 textFont (font);
}
 void draw(){}
 
 void keyReleased() {
if (keyCode != 144) {
   i+=50;
  text(key,i,100);
   }

 }
Page Index Toggle Pages: 1