Web Analytics Made Easy -
StatCounter jQuery.event.trigger({ type : 'keypress', ... - CodingForum

Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • jQuery 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; Sep 9, 2011, 06:22 AM.

  • #2
    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.
    .My new Javascript tutorial site: http://reallifejs.com/
    .Latest article: Calculators — Tiny jQuery calculator, Full-fledged OOP calculator, Big number calculator
    .Latest quick-bit: Including jQuery — Environment-aware minification and CDNs with local fallback

    Comment

    Working...
    X
    😀
    🥰
    🤢
    😎
    😡
    👍
    👎