How To Simulate Keypress Using Javascript?
Is it possible to simulate key press using JavaScript? For example, How can I simulate Ctrl+Alt+ArrowKey? I want to simulate special keys. Is there any API/Framework available? Let
Solution 1:
If your goal is to achieve a browser analog of a sendKeys function (a function where you send keystrokes directly to the keyboard buffer) then you will be unable to achieve this. Triggering key events in a browser sends events to DOM handlers not the keyboard buffer. For this reason simulating an actual working keyboard in the browser which sends strokes to the keyboard buffer is impossible without a security breaching hole from the browser into the OS.
Solution 2:
You could use jQuery
see example below:
function keyPress(char) {
jQuery.event.trigger({ type : 'keypress', which : char.charCodeAt(0) });
}
Post a Comment for "How To Simulate Keypress Using Javascript?"