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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:33:30+00:00 2026-06-17T19:33:30+00:00

I am connecting to a terminal emulator using a library in android, this connects

  • 0

I am connecting to a terminal emulator using a library in android, this connects to a serial device (a switch) and shows me sent/received data. I send data over the connection via a text box below the terminal or by typing in the terminal itself and hitting enter on the keyboard in both cases. It will only ever be a soft keyboard that is used. If I send an incorrect string I am in an unrecoverable state so I had to provide a delete key implementation.

This works ok, if I select the terminal I can delete data. However if I select the editText there is a problem. If I press delete then one character is deleted but two appear to be on on the terminal. So if I write “enable” and hit delete it will change to “enab” on the terminal screen but what would actually be sent is “enabl”. So what I need to do is figure out when the editText is in focus and if it is do not run these lines

  mSession.appendToEmulator(cmdLeft, 0, cmdLeft.length);
  mSession.appendToEmulator(cmdErase, 0, cmdErase.length);

I’ve incorporated this: http://developer.android.com/reference/android/view/View.OnFocusChangeListener.html

The only problem is that if I change focus from editText to terminal it deletes a character sometimes, I need it to actually wait for a delete key to be pressed. It doesn’t happen all the time, but it seems to get stuck in some state where it always thinks the keycode is delete and every time I switch between focus’ a delete occurs. Should I reset the keycode after it is run or something? Why is it getting stuck thinking the keycode is delete? Even after I’ve pressed enter and so on. It occurs when I press delete in the editText and it is empty. If the editText is empty, and there is data in the terminal it correctly deletes that data but triggers this bug. Also if there is nothing in the editText and nothing in the terminal, nothing is deleted but the bug is triggered.

public boolean dispatchKeyEvent(KeyEvent event) {
    if (event != null && event.getAction() == KeyEvent.ACTION_UP) {

        return false;
    }
if(event.getKeyCode() == KeyEvent.KEYCODE_DEL){

    mEntry.setOnFocusChangeListener(new OnFocusChangeListener(){
        @Override
        public void onFocusChange(View v,boolean hasFocus){

              if (!hasFocus) {
                    mSession.appendToEmulator(cmdLeft, 0, cmdLeft.length);
                    mSession.appendToEmulator(cmdErase, 0, cmdErase.length);
                    Log.d(TAG, "in inner delete");
              }
        }          
    });

    Log.d(TAG, "in delete in delete in delete in delete");
    try {
        sendOverSerial("\b".getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
    return super.dispatchKeyEvent(event);
};
  • 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-06-17T19:33:32+00:00Added an answer on June 17, 2026 at 7:33 pm

    This little hack seems to work but I’d really like to know why it is happening/a better solution.

        public boolean dispatchKeyEvent(KeyEvent event) {
        if (event == null || event.getAction() == KeyEvent.ACTION_UP) {
    
            return false;
        }
       if(event.getKeyCode() == KeyEvent.KEYCODE_DEL){
    
        mEntry.setOnFocusChangeListener(new OnFocusChangeListener(){
    
            public void onFocusChange(View v,boolean hasFocus){
    
                  if (!hasFocus && !mEntry.getText().toString().trim().equals("")) {
    
                        mSession.appendToEmulator(cmdLeft, 0, cmdLeft.length);
                        mSession.appendToEmulator(cmdErase, 0, cmdErase.length);
    
                  }
                  else 
                  {
                        mEntry.setText(" ");
                  }
            }          
        });
    
        try {
            sendOverSerial("\b".getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    
        return super.dispatchKeyEvent(event);
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am connecting to a terminal emulator using a library in android, this connects
I am connecting to a terminal emulator using a library in android, this connects
I am connecting to a terminal emulator using a library in android, this connects
I am connecting to a terminal emulator using a library in android, this connects
I am trying to connect to a terminal emulator using a library in android,
Updated question: I am trying to connect to a terminal emulator using a library
We have a terminal emulator (its more then just this, but for the question
I am programming a Windows CE 6 device (Motorola MC3100 scanner Terminal). Using Lazarus
Background To capture data from a logic controller, I'm using screen as a terminal
When connecting to sql server, I have the hardcoded string (local). Is this a

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.