53731

change keyboard layout with javascript

I have a html form. Users can fill in the form in both english and persian languages. but I have a captcha input that users should fill it in english.

If the user's keyboard layout is persian what is typed in this field should change to english so I need some coded that change the keyboard layout on focusing on this input text.

Is it possbile to change keyboard layout with javascript??

Answer1:

You won't be able to change the keyboard layout using JS, but you can capture the keydown event and replace the character with something like this:

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(); } });​

Recommend

  • Best way to block a user from clicking somewhere else than current frame?
  • AngularJS and Tab Order (Disabled Buttons)
  • best backbone.js and require.js boilerplate for huge apps [closed]
  • Prevent focus to URL bar with CTRL + L
  • ViewData, ViewBag and TempData violates MVC? [closed]
  • a concept similar to pointers in as3?
  • LibGdx GLES2.0 cube texel stretching
  • custom string delimiters stringtemplate-4
  • How to open multiple instances of a program in Linux
  • Efficient algorithm to find additions and removals from 2 collections
  • EditText is covered by Keyboard
  • Motorola barcode scanner SDK events C#
  • KnockoutObservableArray with typed elements in TypeScript
  • jQuery: How to AJAXify WordPress Search?
  • Android device acting as an accessory
  • WPF version of .ScaleControl?
  • Android Activity.onWindowFocusChanged doesn't get called from within TabHost
  • Unable to decode certificate at client new X509Certificate2()
  • Retrieving value from sql ExecuteScalar()
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • MySQL WHERE-condition in procedure ignored
  • Cassandra Data Model
  • Web-crawler for facebook in python
  • align graphs with different xlab
  • Calling of Constructors in a Java
  • Traverse Array and Display in markup
  • Transpose CSV data with awk (pivot transformation)
  • KeystoneJS: Relationships in Admin UI not updating
  • Codeigniter doesn't let me update entry, because some fields must be unique
  • trying to dynamically update Highchart column chart but series undefined
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • Hits per day in Google Big Query
  • Authorize attributes not working in MVC 4
  • Checking variable from a different class in C#
  • Busy indicator not showing up in wpf window [duplicate]
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • Python/Django TangoWithDjango Models and Databases
  • java string with new operator and a literal
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize