KMKfw / kmk_firmware

Clackety Keyboards Powered by Python
https://kmkfw.zulipchat.com
Other
1.33k stars 460 forks source link

[Enhancement] Receive hid signal to switch keyboard layer #869

Closed hxse closed 10 months ago

hxse commented 10 months ago

For example, I want to run a script in system background to check windows title. When I playing a game, Script auto send a usb hid signal to switch keyboard layer. When I exit the game, Script auto switch the layer back. I have already completed this function in qmk, but I don’t know how to implement it in kmk, this is my completed repo https://github.com/hxse/py-active-windows-keyboard How does kmk receive hid signals? Also like raw_hid_receive raw_hid_send in qmk.

xs5871 commented 10 months ago

KMK doesn't have a raw_hid endpoint, and there are no plans to implement one. However: Circuitpython offers a second serial interface over USB on most MCUs. There's the serialace module, which is an example of arbitrary code execution via this serial interface. You can use that as a starting point.

hxse commented 10 months ago

@xs5871 I successfully implemented this function. It can automatically switch different layers in the background from detect different windows title. It works well.

KMK keyboard example code: https://github.com/hxse/piantor_kmk_firmware/blob/main/serialace2.py

PC background example code: https://github.com/hxse/py-active-windows-keyboard/blob/main/send_kmk.py

hxse commented 9 months ago

@xs5871 I successfully run Serialace on Raspberry Pi rp2040 keyboard, but I can’t use it with another helios rp2040 keyboard https://github.com/KMKfw/kmk_firmware/issues/880 I'm confused Completely. I still think raw_hid is more stable, i hope support it. like qmk_raw_hid

hxse commented 9 months ago
import usb_cdc
usb_cdc.enable(data=True)

add code to boot.py and connect to the another port, solved my question.