sspanak / tt9

A T9 keyboard for Android devices with a hardware keypad.
Apache License 2.0
224 stars 37 forks source link

Multi-Press Solution like Old T9 Keyboard #399

Closed dlsellers closed 6 months ago

dlsellers commented 9 months ago

This is likely a device-specific issue, so I understand if it's not a priority, but I am using this on the CAT S22 Flip phone, which has a known issue where some keys will frequently register multiple keypresses on a single press. Apparently the 'Old T9 Keyboard' app has a setting called Multi-Press Solution to address this. I'm not sure how that app addresses it, or if it would be possible to integrate something similar into TT9, but I'm at the point where I am frequently unable to text at all because of this issue, so I'd love to know if there's a way to address this within TT9. Thank you!

Ham5andw1ch commented 9 months ago

Just came here to post this. I'm also having similar issues with double pressing. The phone was perfect for a week and then started having really bad keyboard issues. I would switch over to Old T9 Keyboard, but the amount of screen clutter is just unreasonable.

dlsellers commented 9 months ago

Just came here to post this. I'm also having similar issues with double pressing. The phone was perfect for a week and then started having really bad keyboard issues. I would switch over to Old T9 Keyboard, but the amount of screen clutter is just unreasonable.

I also switched over to OT9 until a similar fix is available here. It's actually not so bad if you pay the measly $4 for premium. Then you can hide the on screen keyboard and it's a pretty decent experience. Loads less frustrating than dealing with the double clicks.

Ham5andw1ch commented 9 months ago

Looking at Old T9, it looks like they use a key debounce time check. So if I double press a button fast intentionally, it doesn't register. I know roughly where in the code this could be implemented, so I might try taking a stab at a PR

dlsellers commented 9 months ago

Looking at Old T9, it looks like they use a key debounce time check. So if I double press a button fast intentionally, it doesn't register. I know roughly where in the code this could be implemented, so I might try taking a stab at a PR

You would be my hero if you can make this a reality. If time is an issue, I could probably help, if you point me in the right direction to find the OT9 code and where it should be implemented here.

Ham5andw1ch commented 9 months ago

Looking at Old T9, it looks like they use a key debounce time check. So if I double press a button fast intentionally, it doesn't register. I know roughly where in the code this could be implemented, so I might try taking a stab at a PR

You would be my hero if you can make this a reality. If time is an issue, I could probably help, if you point me in the right direction to find the OT9 code and where it should be implemented here.

The code itself for OT9 isn't available as it's a closed source application. I'm operating mostly out of hunch since if it were trying to workaround some software issue on the keyboard, I imagine it wouldn't catch me just pressing a key twice. I need to set up my android environment and then I'll see what I can do.

image

In this area, I will just need to make a simple if statement to 1: check if there is a repeat and 2: log the times so I can get a delta. From there, it's as simple as doing an early return of the function if the delta is too low.

Where things get a bit dicey though is there would probably need to be a config option. There's also the question of if this is where @sspanak actually wants the code to be.

Ham5andw1ch commented 9 months ago

@dlsellers I have a fix made and it seems to be working. I'll make a fork and give you an APK sometime in the next couple days

Ham5andw1ch commented 9 months ago

Here's the code. It also has an apk attached in the releases. https://github.com/Ham5andw1ch/tt9/

dlsellers commented 8 months ago

@Ham5andw1ch Amazing work! Thanks so much!

sspanak commented 8 months ago

@dlsellers, @Ham5andw1ch, thanks for the analysis and the suggestion. This problem likely occurs on other phones too. They build really low quality keypads nowadays, so I don't think it is unique to CAT. I am willing to add a new setting for such cases.

I have two concerns about the suggested code.

  1. Most actions are handled on key up, but there are exceptions. For example: "Back", "*" and "#" are sometimes handled on key down. My question would be: is it necessary to apply the fix for all keys, including the functional ones (e.g. "open settings", "change the text case", etc)? From my perspective, it should be enough to fix only typing letters, so to move the changes to TraditionalT9.onNumber(). I am not sure how bad your keypads work though...
  2. Some people type really fast and the 150 ms threshold may be a bit high for them. They will experience missed letters, which is also annoying. I was thinking maybe something within 60-100 ms would be better. Have you measured what is the accidental repeat rate, so that we can adjust the timing as low as possible?
dlsellers commented 8 months ago

@sspanak I haven't been able to measure the accidental repeat rate. I can only go off of my experience so far with Ham5andw1ch's tweaked code. So far, I haven't noticed any missed letters from typing too fast, and my typing speed is fairly quick, but I could see how adjusting the rate lower would be better, just in case. I'm not quite skilled enough to adjust it myself and test, since I'm not sure how to compile apks out of this code, but I'm happy to do some testing if someone can compile a few different apks with different thresholds.

sspanak commented 8 months ago

Alright, maybe 150 ms is acceptable.

So! I would like to focus on other bugs for the next release, meaning it will not go into v27.0, but I'll try to include it after that.

Ham5andw1ch commented 8 months ago

@sspanak

1. Most actions are handled on key up, but there are exceptions. For example: "Back", "*" and "#" are sometimes handled on key down. My question would be: is it necessary to apply the fix for all keys, including the functional ones (e.g. "open settings", "change the text case", etc)? From my perspective, it should be enough to fix only typing letters, so to move the changes to `TraditionalT9.onNumber()`. I am not sure how bad your keypads work though...

You're definitely correct on this one. My implementation was more of a bodge than anything. Just to get the ball rolling and get the keyboard functional for myself. As it stands with just the typing keys, it's seemed to work fine. You gotta understand too that the level of stability this provides is still a drop in the bucket compared to every time the OK button has double clicked or the home or back buttons double click. The debouncing needs to happen at an OS level and that isn't happening.

2. Some people type really fast and the 150 ms threshold may be a bit high for them. They will experience missed letters, which is also annoying. I was thinking maybe something within 60-100 ms would be better. Have you measured what is the accidental repeat rate, so that we can adjust the timing as low as possible?

I think the 150ms threshold is potentially a bit high. I set it high to be safe so that I could get the code block to trigger if I worked at my fastest. I think regardless of what the debounce is set to, there will always be some misclicks that slip through. From that perspective maybe making it a slider or drop down would be good (Maybe 50, 100, 150, and 200 ms options?).

Ham5andw1ch commented 8 months ago

I say this, I might need to re-look at the implementation anyways. The double tapping has reared its ugly head again. I think it might be falling slightly outside the range I set. Or the specific line of code isn't getting hit for some reason. There's a potential we might need to stuff all the debounce times into a dictionary per key.

sspanak commented 8 months ago

The double tapping has reared its ugly head again. I think it might be falling slightly outside the range I set

Not necessarily. If look at the down and up functions in KeyPadHandler, you'll notice that at the very beginning, there is an if that bypasses TT9 if there is no text/number field in focus. If you experience double clicks when navigating around and clicking buttons in apps, that's the reason.

I say this, I might need to re-look at the implementation anyways.

What you've done is the way to go. I would have used the same approach, it just needs to be behind a flag/setting, so that it can be enabled only when necessary. And speaking of this...

From that perspective maybe making it a slider or drop down would be good (Maybe 50, 100, 150, and 200 ms options?).

I think this may be a bit confusing for some people. I would start with an on/off toggle that just enables a reasonable debounce time, say 150 ms, and add a slider only if it is really necessary.

Docbroke commented 8 months ago

I have experienced double tapping with Ham5andw1ch version in one app https://play.google.com/store/apps/details?id=net.one97.paytm when I am trying to input numbers for transfer amount. When I tried old t9 keyboard there was no double tap in this same application. I tried to reproduce same in other apps like calculator where numbers keypad is used, but there was no such issue there. I am using cat s22 flip.

jaggedjimmyj commented 8 months ago

150ms debounce time is really too high for a real use, I had a lot of issues with Ham5andw1ch's mod when tried to deliberately press the same button twice in a row. According to my highly scientific research (roughly estimating by eye), there is no significant latency between symbols appearing when the device decides to double input. I can assume that something like 10-30 ms will be more than enough to mitigate the double input without interfering with the real usage.

dlsellers commented 8 months ago

Based on the other comments above, it looks like I just need to step up my texting game :)

sspanak commented 8 months ago

Based on the other comments above, it looks like I just need to step up my texting game :)

Just measure the double input rate. You could use the commented out Logger.d() calls at the beginning of KeyPadHandler.onKeyUp() and KeyPadHandler.onKeyDown(). Add System.currentTimeMillis() to the debug string and try reproducing the problem.

Based on what @jaggedjimmyj says and given that Old T9 keyboard has a simple on/off setting, that does not interfere with fast typing, I suppose, we can go with a low double click protection of around 60-80 ms, but I would like to see the real numbers first. Then I can work on @Ham5andw1ch solution and enable the protection globally, not only when typing in a text field.

I have experienced double tapping with Ham5andw1ch version in one app https://play.google.com/store/apps/details?id=net.one97.paytm when I am trying to input numbers for transfer amount. When I tried old t9 keyboard there was no double tap in this same application. I tried to reproduce same in other apps like calculator where numbers keypad is used, but there was no such issue there.

I haven't used this one and I don't have a CAT phone, so I can't comment. When you say you don't have a problem with Old T9 keyboard, do you mean it is working properly even with the protection disabled?

And finally, a question to everyone: are you experiencing the same problem with the built-in keyboard that comes with the phone?

Docbroke commented 8 months ago

I haven't used this one and I don't have a CAT phone, so I can't comment. When you say you don't have a problem with Old T9 keyboard, do you mean it is working properly even with the protection disabled? And finally, a question to everyone: are you experiencing the same problem with the built-in keyboard that comes with the phone?

I did little more study on this. I used the same app (paytm) where number input was having multipress issue with tt9 (@Ham5andw1ch version), I selected voice input keyboard (sayboard) as keyboard, and then pressed physical keyboard to enter numbers, it worked without multipress. I also tried original keyboard (kika) it also worked without problem.

After this I removed @Ham5andw1ch version and installed v26 of tt9, it has same multipress issue, in same app. But if I type in other apps/ calculator/whatsapp/telegram there is no multipress issue.

I think issue is something else, it is not related to keypad quality as it occurs only in certain circumstances, in my case only in one app (paytm) with (forced) 123 mode in tt9 keypad only, not in any other app or any other keyboard application. It would be helpful if other users can tell where they are facing this issue.

ghost commented 7 months ago

@dlsellers, @Ham5andw1ch, thanks for the analysis and the suggestion. This problem likely occurs on other phones too. They build really low quality keypads nowadays, so I don't think it is unique to CAT. I am willing to add a new setting for such cases.

I have two concerns about the suggested code.

1. Most actions are handled on key up, but there are exceptions. For example: "Back", "*" and "#" are sometimes handled on key down. My question would be: is it necessary to apply the fix for all keys, including the functional ones (e.g. "open settings", "change the text case", etc)? From my perspective, it should be enough to fix only typing letters, so to move the changes to `TraditionalT9.onNumber()`. I am not sure how bad your keypads work though...

2. Some people type really fast and the 150 ms threshold may be a bit high for them. They will experience missed letters, which is also annoying. I was thinking maybe something within 60-100 ms would be better. Have you measured what is the accidental repeat rate, so that we can adjust the timing as low as possible?

I am having this exact issue with the Cat S22 and have done some research online and everything that I have found lines up with what im seeing on my phone. First, the repeat time for the multi press issue is very fast, so 100ms should be enough, also strangely enough it mostly affects the right side of the keyboard (backspace, 3, 6, 9) i havent had any issues with # yet but it might act up too. But my backspace definitely has the multipress issue so I think that it would be a good idea to leave the fix in for that key as well, it can be annoying when trying to erase one letter and it deletes three.

Ham5andw1ch commented 7 months ago

I actually haven't touched the Cat S22 in over a month as I've swapped to a Qin F21 Pro. I will say that towards the end of December before I moved phones, the double clicking returned even on my build. The problem might be deeper than just key repeats. I think to know for sure, I would need to factory reset the phone and try using just a blank note editor with no play store setup. Just to minimize what's running on the device to begin with.

lieb005 commented 6 months ago

I'm having the same issue. Looking for solutions to this I found a lot of things about adding button presses to a queue thru onclick and it being called throttling not denouncing. https://stackoverflow.com/questions/16534369/avoid-button-multiple-rapid-clicks/16534470#16534470

Using gboard I have the biggest issues on the lock screen. I also can't use it for the calculator because of the double click problem. I've installed a couple input apps in the past couple minutes trying to test things. Most enter garbage - up to 10 times repeat on the key. Old T9 worked. Sometimes if I made a slow button press it would be confused whether I was doing a long press or a double tap. (I know it's water damage & corrosion inside the keyboard lol) (also corners of the touchscreen sometimes jump)

I used to have a qin f21 pro but it was "cheap plastic" durable, not "engineered durable like the CAT phone. The f21 USB port broke within a couple months.

Thank you all for your work on the solution 👍

sspanak commented 6 months ago

Folks, before attempting anything, please try the new v27.0. I have fixed a bug which caused repeated characters sometimes.

From what I understand the CAT phone has hardware issues, but let's first eliminate the software bugs, before proceeding with hacking.

Docbroke commented 6 months ago

The issue is still there with v27.0. I too think it is hardware issue and there may be some service running in background trying to fix the issue in software, but in certain events/apps esp., where direct physical keyboard is exposed ( I noticed this when 123 mode is forced in my payment app), software fix stops working and multi-press issue occurs. I noticed that this issue occurs only with tt9, if I choose some other onscreen keyboard (like dotdash) and then use physical keys to press numbers, then there is no multi-press. Probably in certain situations (like forced 123 mode), whatever background service is correcting multipress fails and exposes tt9 directly. But if tt9 is not in use, there is no such issue with physical keyboard. My current solution is to switch to dotdash keyboard, when using this payment app (paytm), using key-mapper shortcut, and switch back to tt9 when home button is pressed. I choose dotdash because it uses much less screen estate otherwise any other on-screen keyboard works.

sspanak commented 6 months ago

I am a bit confused. @Docbroke, you may be experiencing a different problem. If you repeated numbers occur only with TT9 and only in specific apps, then it sounds more like #300. Just to confirm, could you please check if it happens when dialing a phone number?

Moreover, there is no special "forced" 123 mode. Only the setting is forced. If there is a problem with the input mode, you would notice it even if you manually select 123.

Reading the comments again:

... strangely enough it mostly affects the right side of the keyboard (backspace, 3, 6, 9) i havent had any issues with # yet but it might act up too. But my backspace definitely has the multipress issue...

The phone was perfect for a week and then started having really bad keyboard issues...

Using gboard I have the biggest issues on the lock screen. I also can't use it for the calculator because of the double click problem. I've installed a couple input apps in the past couple minutes trying to test things. Most enter garbage - up to 10 times repeat on the key.

@Ham5andw1ch on his own attempt to fix it:

You gotta understand too that the level of stability this provides is still a drop in the bucket compared to every time the OK button has double clicked or the home or back buttons double click.

All this sounds like a hardware problem affecting some keys and getting worse over time. As I understand it happens with any software keyboard, in any app, no matter if there is a text field in focus for typing. This is almost fixable with debouncing.

So, @Docbroke, you may want to follow the other issue I mentioned.

sspanak commented 6 months ago

@Ham5andw1ch , @dlsellers , @jaggedjimmyj , I have added a multi-press protection setting. It is available in version 27.12. @Arabi12321, it does not include Arabic language, so you may want to skip it.

I have added a wide range of possible delay values, from 50 ms to 500 ms. Probably, the extreme ones are useless, but I've decided to put them for flexibility. Please, try out the new version and let me know what works for you.

Also, have in mind this is a beta release and there may be minor bugs here and there. Most important of all, do not try to type while a dictionary is loading, because the app will probably crash. This will be fixed in the final release, of course.

Docbroke commented 6 months ago

@sspanak thanks for your reply. You are right my issue is exactly same as #300. Only thing different is I am using cat s22 flip.

dlsellers commented 6 months ago

Thanks, sspanak! I've been using the 27.12 version since yesterday on the 100ms setting on my Cat S22, and I haven't experienced any issues or bugs so far. I appreciate you getting this change in there!

sspanak commented 6 months ago

This sounds good. I would also appreciate feedback on the highest and the lowest values. I think the 500 ms option is way too high. I can barely type when it is on, so I'll probably remove it. I also wonder if 30 ms is useful at all. Just... if anyone decides to experiment, it would be great to provide feedback, too.