I'd like to send my own generated key events to a <input type="text">.
Acutally this is no problem, with keys like DOM_VK_LEFT. The cursor
goes one char left, but I want to write characters to the text-input.
Until now I have the following working code:
var e = document.createEvent('KeyEvents');
e.initKeyEvent("keypress",true,true,null,false,false,false,false,e.DOM_VK_LEFT,0);
control.dispatchEvent(e);
Does anyone know how I must init the KeyEvent to generate some new
Characters at the actual Cursorposition in the Textfield?
Regards schoetz
> Does anyone know how I must init the KeyEvent to generate some new
> Characters at the actual Cursorposition in the Textfield?
see the constants defined here:
http://lxr.mozilla.org/mozilla/source/dom/public/idl/events/nsIDOMKeyEvent.idl#87
for ordinary letters, the ASCII code is used.
--BDS
var e = document.createEvent('KeyEvents');
e.initKeyEvent("keypress",true,true,null,false,false,false,false,e.DOM_VK_A,0);
control.dispatchEvent(e);
But it doesn't seems to work. :(
Any other ideas?
Thx
schoetz
Benjamin Smedberg wrote:
> Schoetz wrote:
>
>> Does anyone know how I must init the KeyEvent to generate some new
>> Characters at the actual Cursorposition in the Textfield?
>
> see the constants defined here:
> http://lxr.mozilla.org/mozilla/source/dom/public/idl/events
Schoetz wrote:
You can simply manipulate the selection if needed
http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130
--
Martin Honnen
http://JavaScript.FAQTs.com/
Those last two args are the keycode and charcode. The way key events
work in Mozilla is that printable char events have a charcode;
nonprintable ones have a keycode. So you want to be passing "0,
e.DOM_VK_A" for those two args, not "e.DOM_VK_A,0", as far as I can tell.
-Boris
I hope I get it work the other way.
If there is a way to fix this well with the "selection-way"
this is of course also welcome!
Thx
schoetz
Does anybody know a documentation for this function. Exept the W3C docu.
schoetz
Many thanx for this tip. I do not know why there was a problem with
this code when I tried it at home. But now at work it works fine.
Here is my code, if there is anybody looking for it:
e.initKeyEvent("keypress",true,true,null,false,false,false,false,0,e.DOM_VK_A);
schoetz
Boris Zbarsky geschrieben:
> -Boris
##-----------------------------------------------##
Artikel geschrieben mit MyNewsGroups :)
http://mynewsgroups.sourceforge.net
Share your knowledge in... netscape.public.mozilla.dom
##-----------------------------------------------##