How to set default keyboard layout for input boxes, for example when the page gets loaded, we can type in an input text with another keyboard language else than English?
-
??? plase explain better your problem explaining the whole situation and environment you work in.Daniele B– Daniele B2012-05-27 10:06:11 +00:00Commented May 27, 2012 at 10:06
-
Are you talking about, for example, virtual keyboards on touch devices?Pierre– Pierre2012-05-27 10:08:20 +00:00Commented May 27, 2012 at 10:08
-
No i just try to prvent user to pressing ctrl +shift to change the language,ijust set a defualt keyboard layout for an input boxbizzr3– bizzr32012-05-27 10:09:42 +00:00Commented May 27, 2012 at 10:09
-
1@Pierre :) look at answer i configure the meta information and use the lang attribute , it work perfectly for me ;)bizzr3– bizzr32012-05-27 10:13:42 +00:00Commented May 27, 2012 at 10:13
-
if it worked, please check the holo tickbox next to the answer, thanksJeremy Thompson– Jeremy Thompson2012-05-27 10:14:50 +00:00Commented May 27, 2012 at 10:14
|
Show 2 more comments
2 Answers
I'd think about the lang attribute. But this is meta-information, I'm really not sure the browser will do anything with it. Never tried it myself.
<input lang="is" ...>
2 Comments
Jukka K. Korpela
It does not affect keyboard settings at all.
Renan Le Caro
I tried it in codepen, made an input with lang="en" and lang="ru", i have both English and Russian in gboard on Android, and it had no effect either in Firefox for Android or Chrome for Android. I see that duolingo (native app) manages to hint which language to use for text input but maybe that's not yet available via Web APIs. It's a shame, it's super useful when creating language apps
I think that it's possible to catch a keyCode of the button, that was pressed, with javascript and then replace the symbol to the appropriate symbol from array.
This code helps to understand how to catch a keyCode (it does not depend on keyboard language)
<form>
Char: <input type="text" id="char" size="15" /> Keycode: <input type="text" id="keycode" size="15" />
</form>
<script type="text/javascript">
var charfield=document.getElementById("char")
charfield.onkeydown=function(e){
var e=window.event || e
document.getElementById("keycode").value=e.keyCode
}
</script>