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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:48:18+00:00 2026-05-18T01:48:18+00:00

i want to get the key value when user pressed any key and also

  • 0

i want to get the key value when user pressed any key and also perform action based on the key pressed in android.

e.g. if user pressed ‘A’ key then i want to get that value,compare,do something.

  • 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-18T01:48:19+00:00Added an answer on May 18, 2026 at 1:48 am

    Answer to this question should be twofold. It is determined by the way how the key was generated. If it was press on the hardware key, then both approaches described below are valid. If it was press on the software key, then it depends on actual context.

    1.) If key was result of the pressing on the soft keyboard that was obtained by long press on the Menu key:

    You need to carefully override the following function:

    @Override 
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    
        switch (keyCode) {
            case KeyEvent.KEYCODE_A:
            {
                //your Action code
                return true;
            }
        }
        return super.onKeyDown(keyCode, event);
    }
    

    2.) If your activity contains EditText, and softkeyboard was obtained from it, then first approach does not work because key event was already consumed by EditText. You need to use text changed Listener:

    mMyEditText.addTextChangedListener(new TextWatcher()
    {
        public void afterTextChanged(Editable s) 
        {
        }
        public void beforeTextChanged(CharSequence s, int start, int count, int after) 
        {
            /*This method is called to notify you that, within s, the count characters beginning at start are about to be replaced by new text with length after. It is an error to attempt to make changes to s from this callback.*/ 
        }
        public void onTextChanged(CharSequence s, int start, int before, int count) 
        {
        }
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get the string length when a key is pressed like StackOverflow
I want to design a webform that user should fill some fields. The value
I want to get the primary key column value for the rows which were
I want to get all the values(multiple) of a particular key.But i m getting
So I want to get a key to use Google API in Eclipse with
I want get all of the Geom objects that are related to a certain
I want to open an activity depends on the value user select on a
I've got an multi-array (currently with objects) that I want to reorder based on
My project requires a file where I will store key/value pair data that should
I have an application that sends data based on user interaction (not user input).

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.