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.
Page Index Toggle Pages: 1
keyboard input (Read 1540 times)
keyboard input
Oct 31st, 2009, 3:47am
 
Hello everybody.
I don't know how the keyboard input works. If I press key a, x = x+1. How have I to program this?
And witch key has witch number?

Greez Nick
Re: keyboard input
Reply #1 - Oct 31st, 2009, 6:48am
 
Let see.
Above, I see a bar of links. Among them, "Learning" seems promising.
Nothing directly related, but there is a sub-bar. Why not "Basics"?
Lot of stuff there, a quick search shows Keyboard and Keyboard Functions.
Looks suited to your needs.

(You know, this Chinese adage about giving fish and teaching to fish...)
Re: keyboard input
Reply #2 - Nov 1st, 2009, 11:09am
 
Yes I saw that, but I don't understand this. I don't want change the colour and all that. And if I program only that what i need, it doesn't works.

Can you say me how I have to program this:
if key 'a' pressed, x = x+1

I think it needs 3 or 4 lines for this, and I don't wont try all the day to find a solution...
Re: keyboard input
Reply #3 - Nov 1st, 2009, 11:32am
 
Nick93 wrote on Nov 1st, 2009, 11:09am:
And if I program only that what i need, it doesn't works.

Show what you tried.
Re: keyboard input
Reply #4 - Nov 1st, 2009, 11:33am
 
trying is actually the best way to learn it. if we paste the code, you probably have to ask again if you want some slight changes...

this http://processing.org/reference/key.html
and this http://processing.org/reference/keyPressed_.html
gives you all you need.

If it still doesnt work, you can ask again.
Re: keyboard input
Reply #5 - Nov 1st, 2009, 12:20pm
 
That helped me more. But if i program this:

size(500,500);

int value = 0;

void draw() {
 fill(value);
 rect(25, 25, 50, 50);
}

void keyPressed() {
 if (value == 0) {
   value = 255;
 } else {
   value = 0;
 }
}

it doesn't accept 'void'.

I can't program very well, so perhaps its better if I learn at first a bit more and try it again later  Smiley Thanks for your help.
Re: keyboard input
Reply #6 - Nov 1st, 2009, 12:30pm
 
size() must be placed in setup (and the first line in setup too):

Code:
int value = 0;

void setup() {
 size(500,500);
}

void draw() {
fill(value);
rect(25, 25, 50, 50);
}

void keyPressed() {
if (value == 0) {
  value = 255;
} else {
  value = 0;
}
}


Maybe you should look over the getting started tutorial Wink
Re: keyboard input
Reply #7 - Nov 1st, 2009, 2:04pm
 
Yes I think too  Grin

Now it works very good  Smiley
Page Index Toggle Pages: 1