473,320 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

InternetExplorer fireEvent, keyEvent (onscreen JScript keyboard)

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/tutoria...ript/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);
---

Just appending the character works, but is not optimal. Does anyone has
a solution for this IE problem?

Aug 19 '06 #1
2 9188


ha*********@gmail.com wrote:

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);
---

Just appending the character works, but is not optimal. Does anyone has
a solution for this IE problem?
IE allows you to manipulate the selection so instead of doing
this.input.value += key;
you could try e.g.

var range = document.selection.createRange();
if (range.parentElement() === this.input) {
range.text = key;
}

That would then insert the key string or character at the caret
respectively if there is a text selected it would replace the selected
text with the key string or character.
The problem however is that any element being clicked to trigger the
above code might change the selection so often you then need the
unselectable attribute
<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/properties/unselectable.asp>
e.g.
<input type="button"
value="a"
onclick="setKey(this.value);"
unselectable="on">
<input type="text" name="yourInput">

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 19 '06 #2
Martin Honnen skrev:
you could try e.g.

var range = document.selection.createRange();
if (range.parentElement() === this.input) {
range.text = key;
}

That would then insert the key string or character at the caret
respectively if there is a text selected it would replace the selected
text with the key string or character.
The problem however is that any element being clicked to trigger the
above code might change the selection so often you then need the
unselectable attribute
Thank you! It is not quite what I hoped for, but working better ever
the less. I where again really hoping for a relatively unknown IE
"hack" that would allow one to trigger real key events.

Thank you for your answer.

Aug 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

29
by: Christopher Brandsdal | last post by:
If I have a .ASP page that runs JScript code - is it possible to include an ..ASP page that runs VBscript???
17
by: znndrp | last post by:
Hi all, Anyone knows how to use fireEvent to simulate a shit+keypress in a textarea? thanks, -- ,_, (O,O) ( )
2
by: lulu | last post by:
Hello! I am getting the error 'automation server can't create object ' when trying to create new IE instance in jscript : var ie = new ActiveXObject('InternetExplorer.Application'); ie.visible...
3
by: true blue | last post by:
below is a simple program to check key event ,it doesnt give any error nor an exception at runtime plz tell where im goin wrong code<text> import java.awt.*; import java.awt.event.*;
5
by: dwb0407 | last post by:
I am testing out an idea for an IE7 only user base. The idea is that there are a bunch of Input fields on a form. Each field validates itself "onblur" like so. I want logically should be able to...
1
VACEPROGRAMER
by: VACEPROGRAMER | last post by:
I'm making a VB 2003 OnScree keyboard and I ned help. So i need code how to send leter to Word for exsample. And how to make a focus on the Word App. So any help . . . Please VxE
0
by: michels287 | last post by:
I have a masked textbox on my form. I have an onscreen keyboard with numbers only. The masked format for the masked textbox is: (###) ### - #### I want to make sure they enter the phone...
2
mrjohn
by: mrjohn | last post by:
Hey, I'm trying to make a program that will recognize when certain keys are released, so that I can encorperate it into a game I'm making. Unfortunately, it doesn't seem to be working. When I run the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.