Is there a way to write a greasemonkey script to register hotkeys?

I am using a Wiki app that has buttons for indentation and list items. I would like to write a greasemonkey script to capture Ctrl + M and Ctrl + Shift + M for indentation and outdent, respectively. Is it possible?

+2


a source to share


3 answers


Yes, I may have used scripts that used to rely on hotkeys. I'm not familiar with writing greasemonkey scripts, but since it's just JavaScript, I believe you can use jQuery and a plugin like this http://plugins.jquery.com/project/hotkeys . Using this plugin, doing what you want to do is as easy as



$(document).bind('keydown', 'Ctrl+M', fn);

+2


a source


You can do this quite easily. You will need to add event listeners to the input (textarea?). Here's an event tester so you can figure out what keyboard event properties and values ​​you're looking for: http://unixpapa.com/js/testkey.html

For example, control-shift-M gives you this keyup event in Firefox:



keyup     keyCode=77 (M)    which=77 (M)    charCode=0        
          keyIdentifier=undefined keyLocation=undefined
          shiftKey=true ctrlKey=true altKey=false metaKey=false

      

0


a source


If you need any documentation on how to use key events read the MDC documentation here . Basically, while you just want to add an event listener to an element document

or to some element of the document, then the event listener must determine if the desired keys (and only those keys) were pressed, if so, take the appropriate action.

0


a source







All Articles