svenlr / swift-map

Home row computing on Linux and Windows. Navigating in your code made a lot easier with fast access to arrow keys on the keyboard homerow (ijkl) using an overlay activated by a modifier key of your choice.
MIT License
19 stars 2 forks source link

Mapping multiple keys to other keys #6

Open adamschoenemann opened 6 years ago

adamschoenemann commented 6 years ago

Hi, it's me again! The only thing I'm missing now is the ability to map a key with multiple modifiers to another key. That is, I for example have mapped Caps+p to { which works fine, but I'd also like to map Caps+Alt+p to [. I suppose one way to do it would be an extra overlay with "Caps+Alt", which would be fine for me as long as you could have many overlays.

Thanks again!

svenlr commented 6 years ago

Hello again! I implemented your suggestion on the restricting-modifier-keys branch, at least in the command overlay (which is used if "mapped_sequences" is specified). This is how your example would look like in config.json (please remove the other entry with "key_code": 33 first). Note that I did not commit it to the branch this time.

      {
        "key_code": 33,
        "mapped_sequences": {
          "down": [
            {"key": "braceleft"}
          ],
          "if_modifiers": {
            "Alt": {
              "down": [
                {"key": "bracketleft"}
              ]
            }
          }
        }
      }

Why we have to use the command overlay for now for modifiers: It would be a lot more complicated to implement it in the overlay in the system keyboard configuration (xkb) directly, which I am doing right now for simple "mapped_key_label" and "mapped_key_sym". As far as I understand, only two xkb overlays are supported. However, on my system, only one actually worked. I will try to do more with the system keyboard configuration when I have time.

TL;DR: python-xlib required for this solution.

adamschoenemann commented 6 years ago

Impressive! I don't have time to test it out right now, but I will get around to it soon. Again, thanks for the swift turnaround.

adamschoenemann commented 6 years ago

It works! Good work! Although I've discovered that using "mapped_sequences" the "key" values are interpreted back to a keycode using the keyboard layout of the actual keyboard. For example, right now I'm on a computer whose hardware keyboard is US, but I'm using a Danish keyboard layout, and therefore the "braceleft" keysym maps to "å" (since the keyboard has the "{" key where a Danish layout has "å"). It seems to work fine when using "mapped_keysym", so it's only a problem with "mapped_sequences". But I managed to work around it by using modifiers :)

svenlr commented 6 years ago

This seems to happen because a single key_code can generate multiple keysyms. It is possible to get the key_code that generates a given keysym (this is what I am doing), but I have not found out until now how to get the required modifiers, given the keysym. I will get back to this in a few weeks.