-
-
Notifications
You must be signed in to change notification settings - Fork 185
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
Distinguish CAT S22 Flip function buttons #1276
Comments
Thanks for the detailed write up @70mg. I was able to find this issue thanks to the I recently bought the Samsung Trio 500, and I'm using it with a Poco X3 NFC. The keyboard has orange (seems like the color is causing the issue 😆) buttons that can be configured to do certain tasks on Samsung devices. So I thought I can just remap them using the app. However, all special buttons are read as I've searched around and found a related issue #761 which is the main tracking Issue for scan code differentiation. I've asked about it on the Discord, and this feature isn't a short-term priority and would likely have to wait for a couple of months to be implemented. I've noticed that #761 focuses on the ability to choose the source of the button input, like being able to choose either the key code or scan code. But in our case a fallback would be enough, if the keycode is 0, so I've made a fork with some changes that appear to work on my device. Currently the max key code number is ~300, so I add 1000 to the scan code to be out of the range of possible key codes. Here is the branch: Trimmed Diff+++ b/app/src/main/java/io/github/sds100/keymapper/system/accessibility/BaseAccessibilityServiceController.kt
@@ -310,10 +310,19 @@ abstract class BaseAccessibilityServiceController(
+
+ // Fallback to scanCode when keyCode is unknown
+ val code: Int = if (event.keyCode == KeyEvent.KEYCODE_UNKNOWN) {
+ // Add 1000 to go past possible keyCode values
+ event.scanCode + 1000
+ } else {
+ event.keyCode
+ }
+
coroutineScope.launch {
outputEvents.emit(
ServiceEvent.RecordedTriggerKey(
- event.keyCode,
+ code,
event.device,
detectionSource,
),
// ...
- consume = keyMapController.onKeyEvent(event)
+ // Fallback to scanCode when keyCode is unknown
+ val eventProxy: MyKeyEvent = if (event.keyCode == KeyEvent.KEYCODE_UNKNOWN) {
+ // Add 1000 to go past possible keyCode values
+ event.copy(keyCode = event.scanCode + 1000)
+ } else {
+ event
+ }
+
+ consume = keyMapController.onKeyEvent(eventProxy)
if (!consume) {
- consume = rerouteKeyEventsController.onKeyEvent(event)
+ consume = rerouteKeyEventsController.onKeyEvent(eventProxy)
} If you want to test it you can download the artifact from here, it's the CI variant with a different keystore, so I'm assuming that none of the previously saved settings will work, so make sure to make a backup of everything, as you might have to remove your previous app ✌ Attaching the artifact here, as the CI will remove it in the future: keymapper-2.8.4-ci.1.zip SEO: How well does the Samsung Trio 500 work with smartphones other than Samsung? How to remap the app button on Samsung Trio 500? EDIT: After some more testing and configuration of buttons I've noticed that some buttons, despite having a unique scan code inside of the adb command above, they result in the same scan code inside the app.
|
@kamilkrzyskow That's a smart way of working around it... this is a very quick patch that could be stop-gap solution for now? I think you're correct and Key Mapper should automatically be smart and use the scan code as a fallback if the key code is unkonwn. The user wouldn't have to configure anything but instead of "Unknown key code" we could show "Unknown button, scan code: 123" or something? |
So in general the solution turned out to not be so great as I thought / wanted it to be. Looking at the odd behaviour of the buttons I've noticed that all buttons marked with The saving grace in my case are the APP2 / APP3 special buttons, which both have their own unique EV_KEY signatures I've researched a bit with ChatGPT / Deepseek etc. and there is no other API that can get better results without root access. I'll probably stick it out with this keyboard. I've returned the previous one and after further research this was the best one within my budget. The only competition was the Logitech K380S, the S is important, but it has circular buttons and a vertical enter key, so probably too cumbersome to use for me. However it has Fn-lock which I thought isn't so important, as I can just remap the special button keys (oh how ignorant I was 😞), but now I see that locking the keys to F1-F12 would be way easier to handle...
So given my rant above, yes sure, it should work in case of OPs issue as both buttons do have unique
I don't think that's necessary, as injecting (scanCode + 1000) into keyCode works seamlessly, works with backup/restore too. |
I'll await your PR. See #1394, I want to see if i can somehow use Shizuku to intercept input events at the kernel level... its theoretically possible to detect because getevent has permission, I would just write my own getevent. The holy grail would be being able to consume the input events but I need to learn how that works in Linux. |
#1276 refactor: fallback to scanCode when keyCode unknown
…Keycode so it is static and never changes value potentially breaking the trigger detection
Developer TODO (don't remove)
The CAT S22 Flip* has an orange button on its left side, and a button labeled with a 🕪 to the left of its keypad. Currently, these are interpreted as the same button by key-mapper (
unknown keycode 0 (This device)
). It would be useful if they could be distinguished by KeyMapper, enabling distinct functions.The output of
adb shell getevent -lq
yields distinct values for each button, which I'm guessing implies that distinguishing them is possible.Orange side button
/dev/input/event1: EV_MSC MSC_SCAN 00000023
/dev/input/event1: EV_KEY KEY_NUMERIC_B DOWN
/dev/input/event1: EV_SYN SYN_REPORT 00000000
/dev/input/event1: EV_MSC MSC_SCAN 00000023
/dev/input/event1: EV_KEY KEY_NUMERIC_B UP
/dev/input/event1: EV_SYN SYN_REPORT 00000000
🕪 button
/dev/input/event1: EV_MSC MSC_SCAN 00000010
/dev/input/event1: EV_KEY KEY_MICMUTE DOWN
/dev/input/event1: EV_SYN SYN_REPORT 00000000
/dev/input/event1: EV_MSC MSC_SCAN 00000010
/dev/input/event1: EV_KEY KEY_MICMUTE UP
/dev/input/event1: EV_SYN SYN_REPORT 00000000
I appreciate not many people will have this device to hand, so I am of course on hand to help test or provide any additional information.
*The CAT S22 Flip is sold with a version of Android Go which comes with software for mapping these buttons. However, this is unavailable to users running a custom ROM on the device, making KeyMapper a great alternative. The device has become fairly popular among people wanting a "dumbphone" experience, but not wanting to ditch Android. A popular reason for wanting to install a custom ROM (e.g. LineageOS) is to de-google the device. KeyMapper is currently being recommended on the most popular and useful forum post on how to install LineageOS on the CAT S22 Flip.
p.s. KeyMapper is great, thank you!
The text was updated successfully, but these errors were encountered: