Can I do SendKeys in Javascript?

diewland picture diewland · May 13, 2011 · Viewed 85.2k times · Source

SendKeys is method to sending keystroke to an application.
Can I do it in Javascript, to send keystroke in browser ?

REF :
http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx

Answer

rdmueller picture rdmueller · May 13, 2011

If you would be able to send keystrokes on the OS Level, this would be a big security issue. You could (for instance) install any kind of software on the client machine if you where able to send keystrokes to the needed install dialogs.

Yes, you could come up with an active-x control or some other tools to be installed on the client machine. But because of the security issues with such a tool, I wouldn't do it -- even in a controlled environment.

Most of the time, there is a way to achieve your needed functionality without breaching the security.

Update: If you want to jump to the next tabfield, you have to use the focus() method to set the focus to the next element. Unfortunately, you have to find the next element by yourself in javascript, but this should not be a big problem - you can keep an ordered list of all your elements in javascript.

btw: http://forums.devarticles.com/javascript-development-22/moving-to-next-tabindex-on-event-2382.html