Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6725801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:51:01+00:00 2026-05-26T09:51:01+00:00

basically I have to use Processing for a project (not out of choice) and

  • 0

basically I have to use Processing for a project (not out of choice) and have come across a problem regarding the pressing of multiple keys at once. In the keyPressed()function, I have multiple conditionals, each mapping a key to an action. This is all well and good, but supposing I want to press multiple keys at once?

Any suggestions?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:51:01+00:00Added an answer on May 26, 2026 at 9:51 am

    Create an array. Assign a numeric value to each key that you are checking, then turn on the corresponding value in the array on or off whenever a key is pressed or released. Then in the draw() you check the values of the array to see which are on and off at any given instant.

    boolean[] keys = new boolean[4];
    final int A = 0;
    final int D = 1;
    final int W = 2;
    final int S = 3;
    
    void setup() {
    
    }
    
    void draw() {
    
     if (keys[D]) {
       // do something;
     } 
    if (keys[A]) {
       // do something;
     } 
    if (keys[W]) {
       // do something;
     } 
    if (keys[S]) {
       // do something;
     } 
    
    } // end of draw()
    
    
    void keyPressed() {
       int mybutton = key;  // the ascii value of the key that was pushed
    
         switch (mybutton) {
          case 101: 
            keys[D] = true;
            break;
          case 97: 
            keys[A] = true;
            break;
          case 44:
            keys[W] = true;
            break;
          case 111:
            keys[S] = true;
            break;
        } // end switch
    
    } // end keyPressed
    
    void keyReleased() {
    switch (mybutton) {
          case 101: 
            keys[D] = false;
            break;
          case 97: 
            keys[A] = false;
            break;
          case 44:
            keys[W] = false;
            break;
          case 111:
            keys[S] = false;
            break;
        } // end switch
    
    } // end keyReleased
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small python script which i use everyday......it basically reads a file
I basically have a page which shows a processing screen which has been flushed
I basically have a unix process running and it is doing some heavy processing
I am fairly new to Servlet Filters and have basically joined a project using
I have a specific project in which I want to use either a scripting
i have a weird problem. Basically, in my settings.py file i have 4 variables
I basically have the following flow: XML -> JSON -> Spring MVC -> jsp
I basically have something like this: void Foo(Type ty) { var result = serializer.Deserialize<ty>(inputContent);
I basically have three tables, posts, images and postimages (this simply contains the ids
I basically have a server set up and I'm accepting new clients(UNIX) and i'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.