Home Download Buy Blog Forum Support

Catching Key Presses

Catching Key Presses

Postby BRascher on Mon Feb 18, 2013 7:48 pm

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
BRascher
 
Posts: 4
Joined: Mon Feb 18, 2013 7:32 pm

Re: Catching Key Presses

Postby C0D312 on Tue Feb 19, 2013 12:44 am

well you can't really catch all the keypresses but you can access a list of recent commands with command_history(index, <modifying_only>) (http://www.sublimetext.com/docs/2/api_reference.html). So you can use that...
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Catching Key Presses

Postby jps on Tue Feb 19, 2013 1:13 am

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.
jps
Site Admin
 
Posts: 3077
Joined: Wed Mar 19, 2008 12:33 pm

Re: Catching Key Presses

Postby adzenith on Tue Feb 19, 2013 4:04 pm

jps wrote:additional API calls will be coming soon in ST3


So excited!
adzenith
 
Posts: 1217
Joined: Mon Oct 19, 2009 9:12 pm

Re: Catching Key Presses

Postby BRascher on Tue Feb 19, 2013 9:27 pm

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 ;)

Regards
Benedikt
BRascher
 
Posts: 4
Joined: Mon Feb 18, 2013 7:32 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 4 guests