Possible Duplicate:
Keyboard shortcuts with jQuery
I want to display a popover window using a shortcut key instead of clicking the icon on the toolbar. Do you have any good idea? Thank you for your help.
Possible Duplicate:
Keyboard shortcuts with jQuery
I want to display a popover window using a shortcut key instead of clicking the icon on the toolbar. Do you have any good idea? Thank you for your help.
I believe this could help you: http://api.jquery.com/keypress/
In the following example, you check if "return/enter" is pressed (which has the number 13).
Abody97's answer tells you how to determine if a certain key combo has been pressed. If you're not sure how to get that key combo to show the popover, this is what you need. Unfortunately, Safari makes this needlessly complicated.
In the global script, you'll need a function like the following to show a popover, given its ID and the ID of the toolbar item that should show it:
You'll also need code to call this function in your global script's message listener, like the following (this sample does not assume you already have a message listener in place):
Finally, in your injected script, the function that listens for the key combo needs to call
dispatchMessage
, as below:(Stick that in place of
showPopUp()
in Abody97's code sample.)Note: If you only have one toolbar item and one popover (and never plan to add more), then it becomes much simpler. Assuming you've already assigned the popover to the toolbar item in Extension Builder, you can just use
in place of the call to
showPopover
in the global message listener, and omit the message value in the call todispatchMessage
in the injected script.Assuming your shortcut is Ctrl + H for instance, this should do:
Here's a reference for JavaScript keyCodes: little link.
Here's a little demo: little link. (It uses Ctrl + M to avoid browser-hotkey conflicts).