How can I send a keyboard shortcut (e.g. Ctrl + C or Alt + Shift) when the cursor goes to the text input field using Javascript?
I do not use jQuery , but I use MS-Ajax. Is it possible to use MS-Ajax DOM?
EDIT 1)
According to @Ghostoy help, I wrote this code:
function simulateKeyPress() { var evt = document.createEvent("KeyboardEvent"); evt.initKeyEvent("keypress", true, true, window, 0, 0, 0, 0, 0, "e".charCodeAt(0)) var canceled = !body.dispatchEvent(evt); if (canceled) { alert("canceled"); } else { alert("not canceled"); } }
but when he called, he got an error:
Error: Object doesn't support property or method 'initKeyEvent'
and then I changed KeyboardEvent to KeyEvents . I got this error:
Error: DOM Exception: NOT_SUPPORTED_ERR (9)
Where is my mistake?
javascript html ajax
Arian
source share