Change keyboard layout using javascript

I have an html form. Users can fill out the form in English and Persian. but I have a captcha tab that users must fill out in English.

If the user keyboard layout is Persian, then what is typed in this field should change to English, so I need some coding that will change the keyboard layout when focusing on this source text.

Is it possible to change the keyboard layout using javascript?

+8
javascript keyboard-events
source share
1 answer

You cannot change the keyboard layout using JS, but you can capture the keydown event and replace the character with the following:

http://jsfiddle.net/SxdKZ/

$('textarea').on('keydown', function(e){ console.log(e.keyCode); if( e.keyCode == 90 ){ e.preventDefault(); $(this).append('y').focus(); } if( e.keyCode == 89 ){ e.preventDefault(); $(this).append('z').focus(); } });​ 
+6
source share

All Articles