Skip to content

Instantly share code, notes, and snippets.

@zeroeth
Last active December 20, 2015 06:29
Show Gist options
  • Select an option

  • Save zeroeth/6086045 to your computer and use it in GitHub Desktop.

Select an option

Save zeroeth/6086045 to your computer and use it in GitHub Desktop.
multiple keypresses in processing
// Booleans to hold the key states
boolean keyUp,keyDown;
void setup()
{
size (600, 600);
}
// In our loop we check if the booleans have changed
//
void draw ()
{
background (0);
if (keyUp)
{
fill (255, 0, 0);
rect (10, 10, width-20, height/2-20);
}
if (keyDown)
{
fill (0, 0, 255);
rect (10, height/2+20, width-20, height/2-20);
}
}
// Fired every time a key is pressed
//
void keyPressed()
{
if (key == 'w')
{
keyUp = true;
}
if (key == 's')
{
keyDown = true;
}
}
// Fired every time a key is released
//
void keyReleased()
{
if (key == 'w')
{
keyUp = false;
}
if (key == 's')
{
keyDown = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment