@rloic already provided a link to the sketch, but I’ll answer your other question.
No, LockLayer()
and MoveToLayer()
are not equivalent. LockLayer(N)
toggles the state of layer N
when pressed, activating or deactivating that layer, but leaving all other layers unaffected. MoveToLayer(N)
unconditionally activates layer N
, and also deactivates all other layers (except the base layer).
The distinction matters because the layer stack is index-ordered. Layer N+1
is always above (and when active, its non-transparent keys will be masking) Layer N
, regardless of the order in which they were activated. So, if both layers 2
and 3
are active, pressing LockLayer(2)
will deactivate layer 2
, but would only affect the mapping of keys that are transparent on layer 3
. Pressing LockLayer(2)
again would re-activate layer 2
, but layer 3
will still be the top layer. Pressing MoveToLayer(2)
, however, will also deactivate layer 3
, and will result in layer 2
being active regardless of its previous status.