Sublime Forum

Catching Key Presses

#1

Hi,

as the title says, I am looking for a way to catch all key presses to use them in a plugin I am currently working on.

I want to make a plugin that repeats a (user given) command a (also user given) amount of times. After pressing the shortcut for my plugin the user would enter a number and then another keybinding. My program would then catch all key presses, convert the digits to a number and call the command (associated with the keybinding).

Thanks in advance,
Benedikt

0 Likes

#2

well you can’t really catch all the keypresses but you can access a list of recent commands with command_history(index, <modifying_only>) (sublimetext.com/docs/2/api_reference.html). So you can use that…

0 Likes

#3

Making a command to emulate emacs style repeats isn’t currently possible, at least not without redefining the entire keymap, as Vintage does. However, additional API calls will be coming soon in ST3 that will enable this to be done.

0 Likes

#4

So excited!

0 Likes

#5

Thanks for all the answers!

I have implemented a raw version of the plugin, that uses a input panel (for the number of repetitions) and command_history (as suggested by C0D312 – thanks). I will work to make it more user friendly with the new APIs in 3.0. This now served as an introduction to plugin development for Sublime Text for me :wink:

Regards
Benedikt

0 Likes