Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Sending key event script not working

    I need a script that can send keystroke event. The script should work inside Firefox extension. I found this code but it is not working:

    sendKeyEvent({ keyCode: "DOM_VK_DOWN" });

    How to make the script to work?

    Any help will be greatly appreciated!

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,190
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Quote Originally Posted by peter089 View Post
    I need a script that can send keystroke event. The script should work inside Firefox extension. I found this code but it is not working:

    sendKeyEvent({ keyCode: "DOM_VK_DOWN" });

    How to make the script to work?

    Any help will be greatly appreciated!
    accepts an element and a key letter or keyCode
    Code:
    function simKey(elm, key){
    	var ev = document.createEvent ('KeyEvents');
    	ev.initKeyEvent('keypress', true, true, window, false, false, false, false, key.toFixed ? key : key.charCodeAt(0) , key.toFixed ? key : key.charCodeAt(0));
    
      elm.dispatchEvent(ev);
    
    }
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • Users who have thanked rnd me for this post:

    peter089 (04-05-2013)

  • #3
    New Coder
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks, but how can i use the script to send down arrow keystroke? Sorry, if my question is lame but i am very noob in javascript.

    I am trying to use the script inside this addon - http://forums.mozillazine.org/viewtopic.php?t=72994
    Last edited by peter089; 04-05-2013 at 09:09 AM.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,190
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Quote Originally Posted by peter089 View Post
    Thanks, but how can i use the script to send down arrow keystroke? Sorry, if my question is lame but i am very noob in javascript.

    Code:
    simKey(elm, 40)
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #5
    New Coder
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    It doesn't seem to work.

    What i am trying to do is: i am using the Keyconfig addon to create new key, insert the script and binding it with the Tab key, so when i press Tab key it will send down arrow keystroke.

    I also tried the script with Greasemonkey but still not working.

    I need the script to work with any of these two addons.

    I am using the script this way:

    Code:
    function simKey(elm, 40){ 
    var ev = document.createEvent ('KeyEvents'); ev.initKeyEvent('keypress', true, true, window, false, false, false, false, key.toFixed ? key : key.charCodeAt(0) , key.toFixed ? key : key.charCodeAt(0));
     elm.dispatchEvent(ev); 
    }

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,190
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Code:
    myTextArea.onkeyup=function(e){
     if(e.keyCode==9){
       simKey(myTextArea, 40);
       return false;
     }
    };
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • Users who have thanked rnd me for this post:

    peter089 (04-05-2013)

  • #7
    New Coder
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Still can't make it work but thanks for the effort. Maybe what i am trying to accomplish can't be done with javascript.

    I am trying to use the tab key to select next bookmark in Firefox bookmarks menu and shift+tab to select bookmarks in reverse order and the script should be active when the bookmark menu is open. But i am not sure any more if this can be done with javascript.

  • #8
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,190
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Quote Originally Posted by peter089 View Post
    Still can't make it work but thanks for the effort. Maybe what i am trying to accomplish can't be done with javascript.

    I am trying to use the tab key to select next bookmark in Firefox bookmarks menu and shift+tab to select bookmarks in reverse order and the script should be active when the bookmark menu is open. But i am not sure any more if this can be done with javascript.
    aha, the browser menus are different than the document rectangle.
    i'm not sure there are XUL key handlers that run on the object above window, but if the script uses document.anything, that's too low to reach the menus...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #9
    New Coder
    Join Date
    Apr 2013
    Posts
    39
    Thanks
    2
    Thanked 2 Times in 2 Posts
    why not use the onkeyup , onkeypress and onkeydown events


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •