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 7682681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:37:25+00:00 2026-05-31T18:37:25+00:00

I am using keyboard_key variable from here: //overrides the function keyPressed from lcdui.Canvas protected

  • 0

I am using keyboard_key variable from here:

    //overrides the function keyPressed from "lcdui.Canvas"
    protected void keyPressed(int keyCode){
        keyboard_key = keyCode;
    }

to detect if any key was pressed on a mobile phone.

But it returns only the key that is pressed most lately and it doesn’t tell if any other key might be pressed. Please help!

Btw, I’m using NetBeans 7.0.1 as IDE.

  • 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-31T18:37:26+00:00Added an answer on May 31, 2026 at 6:37 pm

    …it returns only the key that is pressed most lately and it doesn’t tell if any other key might be pressed

    The way you use it in your code snippet, keyboard_key will always contain only the key that is pressed most lately – just because it “has no room” to hold anything more than that.

    Consider using Vector to “memorize” different keys that were pressed.

        //define in your class:
        Vector keysPressed = new Vector(); // to keep track of keys pressed
    
        //overrides the function keyPressed from "lcdui.Canvas"
        protected void keyPressed(int keyCode){
            keysPressed.addElement(new Integer(keyCode));
        }
    

    Side note given the question, you may benefit from studying Java language basics. There are many tutorials available online – just search the web for something like “Java getting started”.

    Depending on your application requirements, consider overriding keyRepeated along with keyPressed.


    If you intend to handle key presses in game-loop fashion (“multiple keys at once” suggest that you may possibly have this in mind), consider another option provided by lcdui.game.GameCanvas API, method getKeyStates():

    Gets the states of the physical game keys. Each bit in the returned integer represents a specific key on the device. A key’s bit will be 1 if the key is currently down or has been pressed at least once since the last time this method was called. The bit will be 0 if the key is currently up and has not been pressed at all since the last time this method was called. This latching behavior ensures that a rapid key press and release will always be caught by the game loop, regardless of how slowly the loop runs…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Stata my text editor is gVim . Using scripts from here and here
How can I detect keyboard event in C language without using third party libraries?
I'm using keyboard events ( keydown and keyup ) to detect exactly when the
I am using Eclipse after coming from a well known commercial IDE. I am
I'm using a slightly augmented virtual keyboard from this tutorial: http://net.tutsplus.com/tutorials/javascript-ajax/creating-a-keyboard-with-css-and-jquery/ The Jquery: $(function(){
How do I prevent the start menu from opening by using the keyboard shortcuts
I have converted C++ source from using GLUT to using SDL/OpenGL The problem is
I read input from the keyboard using scanf() in a while loop and print
How to navigate the image using Keyboard arrow keys in C#. My 1st form
I know how to replace text in a string. But that's using keyboard (ASCII)

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.