Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Microsoft Bluetooth number pad #151

Closed
summersab opened this issue Jan 25, 2023 · 9 comments · Fixed by #174
Closed

Add support for Microsoft Bluetooth number pad #151

summersab opened this issue Jan 25, 2023 · 9 comments · Fixed by #174
Assignees
Labels
enhancement New feature or request

Comments

@summersab
Copy link

I'm impressed that you have resurrected this project. Almost a decade ago, I bought a Microsoft Bluetooth number pad (CDY-00001) and attempted to get it to work. However, it would only ever type numbers no matter what I did. I suspect this app doesn't support the key/scan codes of this particular number pad.

I dumped the keycodes using an app I found, and this is what it produced:

KEYCODE_NUMPAD_0        code=144  meta=2097152  scanCode=82  number='48'
KEYCODE_NUMPAD_1        code=145  meta=2097152  scanCode=79  number='49'
KEYCODE_NUMPAD_2        code=146  meta=2097152  scanCode=80  number='50'
KEYCODE_NUMPAD_3        code=147  meta=2097152  scanCode=81  number='51'
KEYCODE_NUMPAD_4        code=148  meta=2097152  scanCode=75  number='52'
KEYCODE_NUMPAD_5        code=149  meta=2097152  scanCode=76  number='53'
KEYCODE_NUMPAD_6        code=150  meta=2097152  scanCode=77  number='54'
KEYCODE_NUMPAD_7        code=151  meta=2097152  scanCode=71  number='55'
KEYCODE_NUMPAD_8        code=152  meta=2097152  scanCode=72  number='56'
KEYCODE_NUMPAD_9        code=153  meta=2097152  scanCode=73  number='57'
KEYCODE_NUM_LOCK        code=143  meta=2097152  scanCode=69  number='0'
KEYCODE_NUMPAD_DIVIDE   code=154  meta=0        scanCode=98  number='47'
KEYCODE_NUMPAD_MULTIPLY code=155  meta=0        scanCode=55  number='42'
KEYCODE_NUMPAD_SUBTRACT code=156  meta=0        scanCode=74  number='45'
KEYCODE_NUMPAD_ADD      code=157  meta=0        scanCode=78  number='43'
KEYCODE_NUMPAD_DOT      code=158  meta=0        scanCode=83  number='46'

Let me know if you need any further information from me.

On a related note, can you recommend a good on-screen predictive T9 keyboard? Long ago, I used the HTC IME, but it has been abandoned for at least a decade:
https://forum.xda-developers.com/t/mod-htc_ime-mod-v28-v29-v30-v30-1-v31.1844512/

Thanks!

@sspanak
Copy link
Owner

sspanak commented Jan 25, 2023

I suspect this app doesn't support the key/scan codes of this particular number pad.

That's right, the scan codes do not match the Android standard. But this looks like a computer keyboard designed for Windows, so I wouldn't expect it to work properly on Android.

TT9 processes the key codes in this file, where KeyEvent.KEYCODE_0 to KeyEvent.KEYCODE_9 are mentioned.

Now, I guess what you want is doable by simply replacing the constants with Microsoft key codes. But! There must also be a way of detecting this particular keyboard and reading its' codes only when it is connected. It's because Microsoft and Android codes are in conflict and trying to read both will cause undesired side effects. For example, Microsoft "0" = Android "MENU", Microsoft "3" = Android "+" and so on...

Actually, I am not sure whether "scanCode" or "code" from your dump should be used, but either way, the codes are non-standard.

Bottom line is, I don't think I would be able to do it, without having the keyboard in my hands. Also, using a Microsoft keyboard on Android is trully an exceptional use case and supporting it feels like too much effort, especially given the fact I am working on this project in my free time. However, you are welcome to fork the project, replace the key codes as I explained above and hopefuly make it run as you want.

can you recommend a good on-screen predictive T9 keyboard?

I've been looking high and low, but I haven't found one. 🙁 I've heard good words about Type Nine, but it is for iPhone.

@sspanak sspanak added the wontfix This will not be worked on label Jan 25, 2023
@summersab
Copy link
Author

summersab commented Jan 26, 2023

What number pad do you use? Back in the day, this Microsoft keypad was one of the most common (which is why I got it). It's just a Bluetooth device, so connecting it to an Android device isn't any problem.

I captured the keycodes using this app (I omitted values that were all set to 0):
https://play.google.com/store/apps/details?id=aws.apps.keyeventdisplay&hl=en_US&gl=US

What information would you need from the device? I can dump the dmesg data if that would help. Otherwise, I may try building it myself.

Lastly, if you felt like taking a crack at the HTC IME that I mentioned, the developer posted the source to his website. It was the most Nokia XT9-compatible keyboard I'd ever used:
http://www.hallerud.se/htc_ime_mod_dev27.zip

The original thread was here:
https://forum.xda-developers.com/t/mod-htc_ime-8th-june-v27-small-fix.624416/

@sspanak
Copy link
Owner

sspanak commented Jan 27, 2023

What number pad do you use?

Well... the one on my phone. 🙂

Traditional T9 is meant to be used on phones with a keypad:
500c7efac8

That's why I said using an external keyboard/keypad that sends custom codes is very non-standard.

What information would you need from the device? I can dump the dmesg data if that would help. Otherwise, I may try building it myself.

I would need to know how to detect that there is an external device and it is that particular keyboard, so that I could process the Microsoft scan codes, instead of the standard ones. But I have no idea how to this. And I don't think I could do it without being able to play with the real device.

@summersab
Copy link
Author

Ah - I didn't realize that they still made Android devices with an attached number pad. I know flip Android phones are popular in Japan. I once tried to figure out how their IME works so I could write a T9 IME for touch screens, but I'm a web developer, not an Android developer (I tinker a little here and there, though).

I always thought it would be nice to have an external number pad to type while your phone is in a mount in front of you. Also, it is tactile, so it would make T9 typing easier than a touch screen. That's why I bought my keypad and found this app.

What are your thoughts on the HTC IME? I think I tried to build it awhile back, but I didn't know much about Android development back then. I might have more success if I tried again, now.

@sspanak
Copy link
Owner

sspanak commented Jan 31, 2023

I didn't realize that they still made Android devices with an attached number pad

There have always been. And TT9 is made exactly for them. I couldn't find any other free and well-working keyboard for Android, this is why I decided to hack on this project and make it better. I actually use it as the primary keyboard on my phone now.

What are your thoughts on the HTC IME?

I took glimpse of the code and I wasn't so impressed. There several small classes and a huge one that contains all the logic. It's some 5000 lines long. Personally, I don't like such huge files that do everything.

But let's assume you are OK with the above. In that case, based on my initial experience with TT9, you may face issues building the project, because it was used with a very old version of Android and Android Studio. I had to upgrade all dependencies and refactor some code, that was no longer compatible with newer SDKs, to make it work. I am not saying it will be the same, but there is a high chance of that.

Still, if you feel like having fun, go ahead and do it. I did the same and despite it was more effort than I anticipated, I am now happy. My phone works exactly the way I want it to work. And it will be the same when I buy a new one!

Also, there is a large community of people who dislike touchscreens. I am happy to make their phones usable too.

I'm a web developer, not an Android developer (I tinker a little here and there, though).

I'm a web developer too, but I had three months of free time in 2022 and thought to myself it would be fun to learn something completely new. I had no idea what I was doing at the beginning. I still don't... 😄

@sspanak
Copy link
Owner

sspanak commented Feb 5, 2023

Scratch the above, #169 made me realize Android supports more than one key for the same function and it is in fact still by the standard. There is nothing special about the Microsoft keyboard and there is no need to detect it in a special way.

So in order to support it:

  • Handle KEYCODE_X and KEYCODE_NUMPAD_X the same way.
  • In the settings, try adding support for +-*/..
  • Add "Reverse Key Order" option under "Keyboard". Description: "Enable if you have 7-8-9 on the first row, instead of 1-2-3"

@sspanak sspanak added enhancement New feature or request and removed wontfix This will not be worked on labels Feb 5, 2023
@summersab
Copy link
Author

  • In the settings, try adding support for +-*/..

In the Select Hotkeys settings, you mean?

@sspanak
Copy link
Owner

sspanak commented Feb 6, 2023

In the Select Hotkeys settings, you mean?

Right. I just wrote some notes while I was on the move, not to forget how to do it.

@sspanak sspanak self-assigned this Feb 6, 2023
@sspanak sspanak mentioned this issue Feb 9, 2023
@sspanak
Copy link
Owner

sspanak commented Feb 9, 2023

I have added support for all numpad keys, except Num Lock. It's going to be trickier than the rest, so I am leaving it for now.

@summersab, feel free to try out beta-16.3 beta-16.5 and let me know if something is still missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants