views:

17

answers:

1

I want to mimic some of the Events like Ctrl+D or Ctrl+S Here's a piece of code that I found on StackOverflow but this also is not working

var evt = jQuery.Event("keypress");
evt.keyCode = 100; // d
evt.ctrlKey = true;
$(document).trigger(evt);
A: 

You cannot do this. That would be an incredible exploit if JS had the power to fire those events that are tied to the OS. Actually the browser would have to signal the OS process.

You can, however, trap those key presses with JS and do something else. So if a user has the browser window focused and they type Ctrl + D, JS can interrupt and do something (limited) and prevent the event from getting through to the OS, but this will only apply if the window is in focus too. This is based on the key code though, not the fact that Ctrl + D is tied to any specific OS event (it's not).

tandu