Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

How to disable "keydown event" Opera browser for specific keystrokes ?

I want to write something else than the user type.Code not working in opera



11:44 am on Mar 2, 2010 (gmt 0)

5+ Year Member

Hello, my program is a phonetic script for bangla language. It will act as follows: If a user type "k" in a textarea/text boxt then i'll output the corresponding unicode letter, for example 文 in the textarea/text (as if the user typed 文, not k). But i don't wanna do this for every keystroke, only a few.

Here is my selective code:

<textarea row="10" column="10" AUTOCOMPLETE="OFF" id="input_textbox01" onfocus="return passId(this);" value=''></textarea>

function passId(oTextbox)
var inputbox=oTextbox;

inputbox.onkeydown= function (keyEvent)
oEvent= window.event || keyEvent;
oSource= oEvent.srcElement || oEvent.target;
//////////// should i deal this key press ?

var result=handleKeyboardInput(); // handleKeybaordInput function will change the value of iShouldDealIt if necessary

return result;

inputbox.onmousedown= function (keyEvent)
oEvent= window.event || keyEvent;
oSource= oEvent.srcElement || oEvent.target;
if( oEvent.button == 0)
updateRange(oEvent.rangeOffset); // update the mouse cursor position
return true;


function handleKeyboardInput()
-detect which key is pressed

If (the key belongs to the list that i wish to change) then
■ update source with the replacing value
■ return false so that browser doesn't write anything to the source text/textarea, i mean disable keydown event

return true; // Pressed key is not in my list, Let the browser normally in a keydown event.

// skipped other or detail code


So if {k:1, a:5, m:8} is my selected list then for the input sequece: "s k d a p m" the output should be: "s 1 d 5 p 8"

Now, the code works fine with firefox 3.5, IE 6,7,8 and Chrome 0.4 to 3.

But in opera its not working. There it outputs: "s 1k d 5a p 8m"......Note that although k,a,m were typed but i retured false from handleKeyboard function so that onmousedown event return false, yet its not working.... Its working as if the event is not disabled so after my modification in the textbox it outputs the character also.

What should i do ? How can i disable keydown event for selective keystrokes ? Please help me.



3:42 am on Mar 10, 2010 (gmt 0)

5+ Year Member

I've found my solution. I need to work on keypress event in opera.

Opera can't output the correct code in keypress event ( it gives 46 for both delete and dot button). But in keydown event it gives the correct code. So at first i detected if it were an opera browser, then i took the keycode from keydown event, saved in a variable and finally in keypress performed my tasks.

For other browsers the code will run normally in keydown event. Opera is an exception. You can find the code at: [code.google.com ]

Featured Threads

Hot Threads This Week

Hot Threads This Month