Arian04 / android-hid-client

Android app that allows you to use your phone as a keyboard and mouse WITHOUT any software on the other end (Requires root)
GNU General Public License v3.0
109 stars 4 forks source link

Either stop relying on EditText for reading visible character input or change code to reduce the number of issues I have with it #4

Closed Arian04 closed 1 year ago

Arian04 commented 1 year ago

Current situation: The user focuses an EditText (Labeled "Direct Input") and types into it. A textwatcher compares changes between the contents of the EditText after each change in the text and sends it. The intended use is for the user to keep typing characters without ever tapping on the EditText to move their cursor, as that would mess up the output.

Current issues with this:

Proposed solutions:

  1. Create a custom view that just doesn't display characters that are typed. This might also allow all the input to go straight to the onKeyDown method and consolidate the code that handles input.
  2. Add some code using cursor position to get around the (currently) only known remaining issue with the EditText consuming input that I need to process. This happens when the user presses an arrow key that moves the cursor into text within the EditText, not allowing the onKeyDown function to process it, while also not modifying text, so the textwatcher doesn't pick it up either.
Arian04 commented 1 year ago

Solution 1 seems difficult from the minimal research I've done, so I'm planning on just going with solution 2.

Arian04 commented 1 year ago

setting android:digits="" fixes all mentioned issues, but, since the keys aren't echoed into the EditText, the textwatcher doesn't trigger. onKeyDown doesn't trigger either, so most input is broken (except arrow keys ironically).

Arian04 commented 1 year ago

KeyListener works perfectly for this, the change will be committed and pushed once the code is cleaned up. I think previously I tried using onKeyListener which (I believe) didn't work, and I didn't try KeyListener since I didn't realize it was different from onKeyListener.

Arian04 commented 1 year ago

Fixed in 95484db3cab5ecce0eaa9c293a02af325f8a6432 by changing the way I detect key presses