zmkfirmware / zmk

ZMK Firmware Repository
https://zmk.dev/
MIT License
2.79k stars 2.82k forks source link

Layer change hook #1260

Open scruper opened 2 years ago

scruper commented 2 years ago

Is it possible to add a layer change action hook (e.g. send key combination to change language) before layer activation? It would be very helpful for multi-lang users. One can send lang change before national language layer activation.

joelspadin commented 2 years ago

I assume you mean to press some key combination that changes the OS keyboard locale, then to switch into a layer? Could this be done with a macro that sends a key combination and then &to to switch layers?

scruper commented 2 years ago

I don't think so.

Let's assume there are 3 lang layers with respective custom layouts shortcuts:

  1. Eng - CTRL+SHIFT+1
  2. Ger - CTRL+SHIFT+2
  3. Spa - CTRL+SHIFT+3

And a Sym symbol layer with []{} etc. which always uses Eng OS layout.

Using macro I don't find the way to return to the language layer used before one switched to the Sym layer.

lang X -> CTRL+SHIFT+1 -> {}[] -> lang X

With the proposed hooks it is possible to send the respective OS lang layout change before every lang layer.
It also can be used to auto change an underglow color based on the current layer etc.

scruper commented 2 years ago

Link to the same functionality in QMK: https://github.com/qmk/qmk_firmware/blob/master/docs/custom_quantum_functions.md#layer-change-code-idlayer-change-code

labuut commented 2 years ago

@saesols, hello! I have the same problem. Have you found any solution?

scruper commented 2 years ago

@labuut Hi, nope. I've switched to QMK =(

labuut commented 2 years ago

I think I will follow your example (

jcmkk3 commented 2 years ago

I'm pretty certain that this should be possible with macros and layers. We'd need to see your exact layout to know how to give specific advice, but you should be able to make each of the lang layers also have their own macro that switches to the symbol layer and switches back to the language that you came from.

I think that many folks that need to type in multiple languages use the US international keyboard layout and then create preprocessor macros for the specific keycodes that they need. An example is here: https://github.com/metheon/zmk-config/blob/main/config/mac_iso_danish.keycodes

Another approach is this one: https://github.com/urob/zmk-nodefree-config#international-characters