开发者

How to register a xul window as listener of another?

开发者 https://www.devze.com 2023-02-09 16:45 出处:网络
I have a keylistener that receives a function and calls it when a key is pressed: function addKeyListener(functionToCall) {

I have a keylistener that receives a function and calls it when a key is pressed:

function addKeyListener(functionToCall) {
    addKeyEvent("keypress", function() { functionToCall(arguments[0]) }, false);
}

Wha开发者_StackOverflowt can I pass to that function to let my window be a keylistener?


I'm not quite sure what your code snippet is trying to achieve, but if you have a reference to another window, and you want to listen to key events on that window, simply use otherWindow.addEventListener("keypress", eventHandler, false);.


OK, so given your clarification, it looks as if you need to do the following:

  1. Locate the focused document in the other window: otherWindow.document.commandDispatcher.focusedWindow.document
  2. Create a key event: otherDocument.createEvent('KeyEvents')
  3. Initialise the event (type, code, modifiers etc.) from your key event
  4. Locate the focused element, if any, in the other window: otherWindow.document.commandDispatcher.focusedElement
  5. Dispatch the event to the focused element, or document if no element has focus.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号