Sublime Forum

Pressing Keys with Plugins

#1

I am trying to create a plugin that works with SublimeREPL, I would like to be able to press the ENTER-key within my plugin in order to send a command to the console.

Is this possible/How would I do that?

0 Likes

#2

The default key binding of enter calls insert command.

{ "keys": ["enter"], "command": "insert", "args": {"characters": "\n"} },

I therefore guess you’d need to call

view.run_command("insert", {"characters": "\n"})
1 Like

#3

Thank you, but this wont work! As I have now found out SublimeREPL uses the “repl_enter” command witch i can trigger with “view.run_command(“repl_enter”)” to send commands to the interpreter.

This means I have found out how to solve my problem, but not really the problem I have proposed in my question (Sending actual keypresses to SublimeText). Thus i will not yet add the [Solved]-Tag my post.

0 Likes

#4

I am a little confused here. You can send your enter command to SulimeREPL. deathaxe’s solution will add a newline at the point where the command is run. What precisely are you attempting to do that you can’t with the two solutions?

0 Likes

#5

I can do everything I want to with the two solutions, however I still think sending Keypresses to Sublime Text with Plugins could be useful for other tasks/other people.

0 Likes

#6

Well I don’t deny there is a small subset of problems that might be addressed by more direct API access to the keystream (either in inserting, or analyzing) however I suspect this is a very small subset. Between API command calls, and keymapping and such, uncontrolled access would have to be very carefully considered.

1 Like

#7

A key press enters normal text or is mapped to a predefined command. Therefore the proper way is to call a command. Sending a key press would not necessarily cause the desired command to be called as key bindings can be customized by users.

What I posted was just the default binding of “enter”, which is bound to insert("\n"). Didn’t know REPL binds this key to a different command. But this example proofs my former statement. Sending keys is useless.

0 Likes