Sublime Forum

Key Binding problems with non-US keyboard

#1

Hi,

Some of the default Key bindings are not usable on my (Scandinavian) keyboard. E.g. ctrl+ or ctrl+] are not possible, as the ]-characters always require Alt to be pressed as well.

I tried making my own key bindings by comparing my keyboard layout to a US layout and changing the default bindings accordingly (the idea was to map the commands to the same physical locations as on the US layout). The resulting user-binding file:

    { "keys": "ctrl+¨"], "command": "indent" },
    { "keys": "ctrl+å"], "command": "unindent" },

    { "keys": "ctrl+¨"], "command": "show_overlay", "args": {"overlay": "goto", "text": "#"} },

    { "keys": "ctrl+-"], "command": "toggle_comment", "args": { "block": false } },
    { "keys": "ctrl+shift+-"], "command": "toggle_comment", "args": { "block": true } }

    { "keys": "ctrl+§"], "command": "show_panel", "args": {"panel": "console", "toggle": true} },

    { "keys": "ctrl+shift+å"], "command": "fold" },
    { "keys": "ctrl+shift+¨"], "command": "unfold" }
]

However, the only bindings that seem to come through are the ctrl± and ctrl+shift± which do get mapped to toggle_comment. All other mappings do not work.

I troubleshooting by enabling command logging (by writing sublime.log_commands(1) in the console window), but it only shows which commands are getting activated, not how Sublime Text interpreted the keyboard combo that triggered it, so I don’t see a way to find out what I should actually write into the Key bindings file to get things working with the keys I would like.

Any ideas? Is this by any chance related to the reportedly lacking Unicode support in Python 2 (wiki.python.org/moin/Python2orPython3)?

0 Likes

#2

Your best bet is to use sublime.log_input(True) in the console, to see the key names that are getting sent to Sublime Text

0 Likes

#3

Thanks for the tip! That allowed me to see what Sublime thought was being pressed. It seems that when I use only single keys at a time, they are correctly interpreted; but when certain keys (that differ between the US/UK and Scandinavian layouts) are used in combinations with Alt or Ctrl, they are often read incorrectly:

Table: Sublime's interpretation of keys in alt/ctrl combos on Swedish/Finnish keyboards
  Actual key  | 
  used in the | Sublime reads
  combination | key as
  ------------+--------------
       ¨      |      ;
       å      |      ]
       §      |      \
       ´      |      
       '      |      /
       +      |      =

Swedish/Finnish keyboard:

UK Keyboard:

As a result, I was able to get commands mapped to the same physical keys as on the UK keyboard layout. Its not a very satisfactory solution though, because the menu labels for the keyboard shortcuts now are just plain wrong and give no memory aid for remembering the shortcuts.

If anyone knows the answer, I’m still interested to know what the underlying problem is - Python’s Unicode support or somehting else? Any hope of Sublime switching to Python 3 (if that would help) or correcting this in some other way?

0 Likes

#4

This is a natural result of the virtual key code system in Windows, and isn’t related to Python.

0 Likes