H
hans.duedal
The Gecko DOM reference gave me the idea that an onscreen keyboard I
was doing should use Key Events, so the user may for instance place a
letter anywhere, and such. While this can be handled using a number of
hacks, I really want to use events, since they seem like the "right"
way to do an onscreen keyboard.
Just fire the key events associated with the button on screen right?
With Firefox this worked great, and so did it for IE, BUT, IE does fire
the events, and I can capture them as well, but no letters appear in
the textarea, since this is handled otherwise.
I use this tutorial for reference:
http://www.howtocreate.co.uk/tutorials/javascript/domevents
Today I am forced to do it this way:
--- snip ---
if( document.createEvent ) {
if( window.KeyEvent ) {
var evObj = document.createEvent('KeyEvents');
evObj.initKeyEvent( 'keypress', true, true, window, false, false,
false, false, 0, key.charCodeAt(0) );
} else {
var evObj = document.createEvent('UIEvents');
evObj.initUIEvent( 'keyup', true, true, window, 1 );
evObj.keyCode = key.charCodeAt(0);
}
this.input.dispatchEvent(evObj);
} else if( document.createEventObject ) {
this.input.value += key;
}
--- snip ---
the IE code would go something like this:
---
var evObj = document.createEventObject();
evObj.keyCode = key.charCodeAt(0);
evObj.repeat = false;
evObj.returnValue = true;
this.input.fireEvent('onkeypress',evObj);
was doing should use Key Events, so the user may for instance place a
letter anywhere, and such. While this can be handled using a number of
hacks, I really want to use events, since they seem like the "right"
way to do an onscreen keyboard.
Just fire the key events associated with the button on screen right?
With Firefox this worked great, and so did it for IE, BUT, IE does fire
the events, and I can capture them as well, but no letters appear in
the textarea, since this is handled otherwise.
I use this tutorial for reference:
http://www.howtocreate.co.uk/tutorials/javascript/domevents
Today I am forced to do it this way:
--- snip ---
if( document.createEvent ) {
if( window.KeyEvent ) {
var evObj = document.createEvent('KeyEvents');
evObj.initKeyEvent( 'keypress', true, true, window, false, false,
false, false, 0, key.charCodeAt(0) );
} else {
var evObj = document.createEvent('UIEvents');
evObj.initUIEvent( 'keyup', true, true, window, 1 );
evObj.keyCode = key.charCodeAt(0);
}
this.input.dispatchEvent(evObj);
} else if( document.createEventObject ) {
this.input.value += key;
}
--- snip ---
the IE code would go something like this:
---
var evObj = document.createEventObject();
evObj.keyCode = key.charCodeAt(0);
evObj.repeat = false;
evObj.returnValue = true;
this.input.fireEvent('onkeypress',evObj);