473,425 Members | 1,670 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,425 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 9194


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: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.