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 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2005
    Posts
    23
    Thanks
    11
    Thanked 0 Times in 0 Posts

    jQuery.event.trigger({ type : 'keypress', ...

    I'm trying to simulate the combination of the keydown/keypress events 'ctrl' and '+', with
    Code:
    var e=jQuery.Event("keydown",{keyCode:17} && jQuery.Event("keypress",{keyCode:107}));
    jQuery("body").trigger(e);
    Anyone who can help me to correct this ?
    Last edited by skynet; 09-09-2011 at 12:22 PM.

  • #2
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Quote Originally Posted by skynet View Post
    I'm trying to simulate the combination of the keydown/keypress events 'ctrl' and '+', with
    Code:
    var e=jQuery.Event("keydown",{keyCode:17} && jQuery.Event("keypress",{keyCode:107}));
    jQuery("body").trigger(e);
    Anyone who can help me to correct this ?
    This is just wrong. Logical and (&&) always results in a boolean, so your code is actually the same as
    Code:
    var e=jQuery.Event("keydown", true);
    jQuery("body").trigger(e);
    which is obviously not going to do what you want.

    The whole thing looks like you don't have much experience with programming in general. With trial and error, you won't get very far.

    Anyway, I don't know what you are trying to accomplish here, but it's probably not going to work: Triggering key events programmatically will simulate those events, meaning it will trigger your own custom event handlers you have bound before. It will never write any actual letters to the screen or trigger any keyboard shortcuts in your browser.

  • Users who have thanked venegal for this post:

    skynet (09-09-2011)


  •  

    Posting Permissions

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