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 › Confused about key / keyPressed
Page Index Toggle Pages: 1
Confused about key / keyPressed (Read 634 times)
Confused about key / keyPressed
Apr 19th, 2009, 7:36pm
 
Hi, I'm trying to make a simple clone of robotron (arcade game with two directional inputs, you move with one and shoot in any direction with the other);

This means I need to be able to use W,A,S,D and the Arrow keys at the same time, often holding down one key in each group. I know keyboards have blocking issues, ie only so many keys in a certain area can be held down and sent at once but I'm sure that my laptop keyboard is capable of what I want.

I'm familliar with using keyPressed() and running an if(key=='x') type of statement inside of it, but this only will return one key at a time. I get weird issues where no key is seen for short periods of time when i'm switching directions very quickly (obviously necessary for an action game)

Basically, what I'm looking for is a simple check to see if a specific key is currently down; I'm fine with checking every frame to see what the states are.  I don't need anything to be run on the actual press event, meaning I don't need information about key repeat rate.

Re: Confused about key / keyPressed
Reply #1 - Apr 19th, 2009, 10:27pm
 
Did you use booleans?
Can you show some code? Smiley
Re: Confused about key / keyPressed
Reply #2 - Apr 20th, 2009, 5:41am
 
You'll want to look at keyCode (http://processing.org/reference/keyCode.html) for your arrows and such.  Select Case statement may be easier.
Re: Confused about key / keyPressed
Reply #3 - Apr 20th, 2009, 7:24am
 
Don't forget out precious hacks section.. has a lot of goodies
http://processing.org/hacks/hacks:multiplekeys

-seltar
Re: Confused about key / keyPressed
Reply #4 - Apr 22nd, 2009, 2:21am
 
Oh duh, I should have checked the hacks section.

Thanks a lot!
Page Index Toggle Pages: 1