Sublime Forum

Get single character input


Is there a way for a plugin to get single character input?



Can you expand a bit on what you’re trying to accomplish?

In general anything that allows you to prompt the user for input interactively requires that they press a minimum of two keys (the single character of input, and Enter to submit it). So in that regard, I don’t think there’s a way to do something like this.

That said, depending on your use case you may be able to make use of key bindings and a custom context to provide single character input.



I’m trying to emulate a behavior of an adaptive editor for handicapped people the provide typing short cuts be it requires me to preprocess keystrokes

trying to setup a programming tutorial



I think the closest you could get to something like that would be a series of key bindings that cover all of the keys that you want to handle and a custom context that makes them only apply when you want them to. Then your code would be informed of every key press and you could handle them as you like.

However depending on the scope of this, that would be a lot of key bindings so that may be a little unweildy. You also can’t currently create a key binding on just a modifier (say to know when someone pressed just Ctrl). It’s been mentioned by Jon on Discord that this capability is coming to a future version, though.



There is package for a Sublime Text “Tutorial”:



You may add a key binding to "keys": ["<character>"], which will call the specified command with an additional character argument. This binding is active for every produced glyph and it cannot be combined with modifiers.

Make sure to add a proper context as otherwise you won’t be able to type normally anymore.

1 Like