kriomant / ch57x-keyboard-tool

Utility for programming ch57x small keyboard
MIT License
485 stars 59 forks source link

Feature request: Trigger scan codes instead of HID codes? #103

Open mscheper opened 3 days ago

mscheper commented 3 days ago

I've uploaded the following config for my 3×4 two-knob keyboard [extract only]:

buttons:
  - ["a", "ctrl-a", "alt-shift", "alt-ctrl,ctrl-b"]
  - ["e", "f", "<224>", "<225>"]
  - ["<100>", "j", "<124>", "<125>"]

I have the keyboard set to the relevant layer, and verified that the letters a, e, f and j function as expected. But unless I'm misunderstanding something, the HID codes, <100>, <124> and <125>, don't match what's actually being sent, as reported by the keyboard monitor. python -m keyboard actually outputs the following, when I press those three keys in order:

{"event_type": "down", "scan_code": 86, "name": "<", "time": 1726591137.448623, "device": "/dev/input/event14", "is_keypad": false}
{"event_type": "up", "scan_code": 86, "name": "<", "time": 1726591137.536329, "device": "/dev/input/event14", "is_keypad": false}
{"event_type": "down", "scan_code": 133, "name": "unknown", "time": 1726591140.22467, "device": "/dev/input/event14", "is_keypad": false}
{"event_type": "up", "scan_code": 133, "name": "unknown", "time": 1726591140.33663, "device": "/dev/input/event14", "is_keypad": false}
{"event_type": "down", "scan_code": 135, "name": "unknown", "time": 1726591141.136603, "device": "/dev/input/event14", "is_keypad": false}
{"event_type": "up", "scan_code": 135, "name": "unknown", "time": 1726591141.224664, "device": "/dev/input/event14", "is_keypad": false}

<224> and <225>, which both python -m keyboard and showkey report are the codes for my brightness adjustment keys (Fn+F5 and Fn+F6 on my keyboard, FWIW), don't produce any output at all.

All the other functions I've tried (namely wheelup, wheeldown, volumeup, volumedown, mute, power, screenlock) work as expected.

Am I misunderstanding these keyboard codes and how they're specified, or is there something else I can try?

Thank you for maintaining this program.

kriomant commented 2 days ago

HID codes are not scan codes. First are converted to last ones by OS.

mscheper commented 2 days ago

@kriomant: Okay. So I assume the HID codes are the ones between angular brackets, and the scan codes are the ones that showkey shows. And from trial and error, I'm finding that the HID codes largely match the _Universal Serial Bus HID Usage Tables_ you linked to.

But it's far from a complete match, and that's part of why I was confused. e.g. According to Cinnamon Seetings' keyboard shortcut settings, <104> is tools; <105> to <109> are launch5 to launch9; <110> is just '0xc5'; <111> is mic mute; <112> is toggle touchpad; <113> is touchpad on. I imagine it depends on the OS, and hopefully I can find what I want from trial and error.

You might want to add a note about that, to where you link to that document. (I can't actually find where that link is right now, though, so maybe you already got rid of it?) And if there's a way to find out what a HID code is from python -m keyboard, then that's not clear to me, either.

Thanks for the reply.

mscheper commented 2 days ago

So my laptop has eight function keys, including the brightness adjustment keys I'm interested in, that do show up in keyboard.py and the Cinnamon keyboard configuration tool, but none of the HID codes trigger them. (HID codes higher than <145> in the YAML file, FWIW, don't produce any scan codes at all, in either tool.)

I suspect we're limited by the hardware, but is it possible to add a feature in your program to trigger scan codes, instead of HID codes? Maybe then I could get the screen brightness codes to work? (It'd be really nice to just turn a knob to turn down the brightness on my screen, instead of having to fumble for a key combination I never seem to remember when it's still dark in the morning.)

There are command line tools that I could launch to adjust the brightness when I press a key, but I suspect they won't perform as well as whatever's responding to the keypresses.

mscheper commented 2 days ago

Actually, I've found another way: In Cinnamon Settings, I can go to Keyboard→Shortcuts→System→Hardware and create additional keyboard shortcuts for brightness adjustments there. I just used <137> and <140>, which Cinnamon sees as otherwise unused hex codes. Perhaps my feature request might still be useful for somebody else, but I no longer need it, so I don't mind if you close this.

Cheers.