creating custom keyboard layout for textarea with javascript and jquery -


i want create keyboard site have keyboard(virtual buttons) textarea.this project devide 2 part:
the first part typing virtual keyboard on site created buttons , javascript ended , works fine.
the second part typing real keyboard our custom language layuot on textarea.
want catch entered keys , checking shift or capslock state in code add appropriate character(that exist in custom layout) textarea.
if want make more simple,i want user keys in qwerty english keyboard , change other characters , add textarea custom keybaord layout.
have 3 event on keys working in javascript , jquery , onkeypress , onkeydown , onkeyup.
problem of onkeyup can't control textarea when user holds key , can't use it.
problem onpressed , onkeydown defualt operation! add qwerty english chars textarea after code , can't find way disabling operation.

example have text "abc" in textarea , cursor place between b , c,the user want type x(suppose in custom keyboard on g key place) in there when presses g key cursor place , other stuffes , add x string "abxc" due onpress default operation add g after x , can't anything,i tryed control keyup problem bigger when user holds key , have "abxgxgxgxgxgxgxgxgxgc"!

how can disable adding chars textarea?

note : between keypress , keydown preffer use keypress becuase can't detect shift , capslock , use own way in code dealing shifted state , capslock.

you can use .preventdefault() stop default behaviour of event happening. (somewhat silly) example illustrates how can disable a button text input or textarea id demo:

$(function() {      $("#demo").keypress(function(event) {         if(event.which == 97) {             //the user pressed "a".             event.preventdefault();         }     });  }); 

what want first check key pressed (using event.which), add replacement key textarea, , call event.preventdefault() stop character user typed being outputted.

since it's onkeypress event outputs character, must use , not onkeyup or onkeydown if want use approach.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -