1

I have a chrome extension that listens keydown on ctrl+shift+u.

If I trigger an event ctrl+shift+u in a content script, the plugin's listener won't fire.

// ( I am using jQuery )

var e = jQuery.Event( "keydown" );

            e.which = 85;
            e.keyCode = 85;
            e.shiftKey = true;
            e.ctrlKey = true;

$( document ).trigger( e );

How can I properly trigger this event? ( preferably from a content script or from another extension )

I would not say this question is a duplicate. I succeeded to trigger the event, only the extension's handler won't fire. This question rather refers to emulating browser actions, not content-based events.

UPDATE:

The extension that listens the event is a third party software, there is no way to dig inside it's code. This keyboard event can be configured on browser-level in chrome://extensions/configureCommands

Xan
  • 74,770
  • 16
  • 179
  • 206
István Pálinkás
  • 2,217
  • 7
  • 25
  • 50
  • Possible duplicate of [Simulate JavaScript Key Events](http://stackoverflow.com/questions/596481/simulate-javascript-key-events) – wOxxOm Dec 02 '15 at 15:13
  • 1
    If that key is defined as a Chrome extension key on `chrome://extensions` page then you won't be able to trigger it programmatically. – wOxxOm Dec 02 '15 at 15:14
  • Apparently you have to use a content script that catches the events and send them to the background process http://stackoverflow.com/questions/5498893/chrome-extension-how-to-get-key-events – Kerstomaat Dec 02 '15 at 15:22
  • 1
    have you tried `chrome.commands` API? https://developer.chrome.com/extensions/commands – dragonjet Dec 02 '15 at 15:23
  • As far as I see, this API rather refers to listening than triggering the event. Please, feel free to correct me – István Pálinkás Dec 02 '15 at 15:57
  • You need to be more descriptive in what you're trying to do. Do you have an extension that somehow listens to this (how)? Is it a third-party extension? Needs more details. – Xan Dec 02 '15 at 16:25
  • Please, read my update – István Pálinkás Dec 02 '15 at 16:39
  • So you're creating an extension that should trigger a keydown in a different extension? You may need to trigger a native keydown, and not a jQuery keydown. – Teepeemm Dec 02 '15 at 16:42
  • Yes, I am trying to do exactly what You've described. I am just not sure if any triggers in the content document will actually trigger the browser-level event. Maybe a chrome API does, but I did not succeed to find it. – István Pálinkás Dec 02 '15 at 16:43
  • Any suggestions to proceed? – István Pálinkás Dec 02 '15 at 16:55

1 Answers1

1

So, your question is thus: How to trigger a command defined in another extension with chrome.commands

That is not possible from extension code if you don't control the extension receiving the event.

You may have success with a Native Host, but that's a very roundabout route.

Xan
  • 74,770
  • 16
  • 179
  • 206