472,958 Members | 2,218 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 9174


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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.