rexxars / sublime-hacker-typer

Pretend you're an expert hacker and can type flawlessly
MIT License
80 stars 9 forks source link

Suggestion for simulating the "keypress" event #1

Open bordaigorl opened 10 years ago

bordaigorl commented 10 years ago

Hi, hilarious idea! I read your notes in the readme about Sublime lacking a keypress event. Here's how you could emulate that, it's a bit hackish but it should work.

You could create a on_query_context listener so you can add a hacker_typer_enabled context to keymaps and then install a keymap with maps for every letter invoking a command to insert text. Instead of a context, the enable/disable command could rename the keymap of the plugin so it is no longer detected by ST (i.e. by adding a -disabled suffix to the filename) so the defaults take over.

rexxars commented 10 years ago

Thanks!

Hmm, this is a really interesting idea. I'll take a look at some point later. Thanks again!

philippotto commented 10 years ago

I ran into the same problem with the never ending loop when invoking a TextCommand in the on_selection_modified listener. I used a simple boolean flag to resolve the problem. Before invoking the command, you toggle the flag so that you can ignore the resulting event.

Just look for the ignoreSelectionCommand variable here.

I could imagine, that this is easier than defining a keymap with every letter and enabling/disabling it correspondingly.