473,396 Members | 1,836 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,396 software developers and data experts.

ctrlKey property in IE

I keep getting 'member not found' error if I try to do the below
command:
//
window.event.ctrlKey = false; // assigning value to property
//

Is it not allowed to change the window.event.ctrlKey value? But
according to the reference in
http://msdn.microsoft.com/library/de...es/ctrlkey.asp
, the ctrlKey property is read/write in IE 5 and later?

Would anybody give me a clue? Is there any way that I can 'cancel' the
pressed ctrlKey?

Thanks!
Hiroshi
Jul 23 '05 #1
10 3385
On 4 Apr 2004 10:10:25 -0700, Hiroshi Ochi <hi**********@hotmail.com>
wrote:
I keep getting 'member not found' error if I try to do the below
command:
//
window.event.ctrlKey = false; // assigning value to property
//

Is it not allowed to change the window.event.ctrlKey value?
I would argue, no, you shouldn't be able to...
But according to the reference in [url], the ctrlKey property is
read/write in IE 5 and later?
....but as you say, they do indicate it's writable. However, Microsoft's
documentation says many things that aren't true, so it's not that
surprising.

I believe that the read/write status is only true under one condition:
when the user creates an event object using Microsoft's
document.createEventObject() method. The event object returned uses
default values, so the user must modify the information as appropriate. It
can then be fired with Microsoft's obj.fireEvent() method[1].

With pre-existing events - that is, those generated by the browser - all
properties are read-only. They are, after all, supposed to represent the
state of the system when the event was fired, so allowing an author to
change that at a whim would corrupt the data.
Would anybody give me a clue? Is there any way that I can 'cancel' the
pressed ctrlKey?


Not directly. You'll have to add some form of logic to ignore the key. If
this is used to change, say CTRL+K to K, you can return a value that
represents the character code of the key, effectively over-riding what the
user did. However, I think this is only supported by IE, and I haven't
tested if it will be of any use - you didn't give enough information.

Hope that helps,
Mike
[1] I keep referring to "Microsoft's" methods, because they do not conform
to the W3C DOM 2 Event specification.

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #2
DU
Hiroshi Ochi wrote:
I keep getting 'member not found' error if I try to do the below
command:
//
window.event.ctrlKey = false; // assigning value to property
//

Is it not allowed to change the window.event.ctrlKey value? But
according to the reference in
http://msdn.microsoft.com/library/de...es/ctrlkey.asp
, the ctrlKey property is read/write in IE 5 and later?

Would anybody give me a clue? Is there any way that I can 'cancel' the
pressed ctrlKey?

Thanks!
Hiroshi


Let me get this straight. The visitor of your webpage presses the <Ctrl>
key and your javascript function will neutralize it in MSIE... or this
is what you want to happen in MSIE. Did I get this right?
Can you explain your webpage context, situation, requirements? What's
its url?

DU
Jul 23 '05 #3
Thanks Michael and DU,

To enhanced usability, I would like to set the TAB behaviour if user
presses 'CTRL + Right Arrow' key and to set the SHIFT + TAB behaviour if
user presses 'CTRL + Left Arrow' key.

I especially need this function in HTML Tables. For the time being, I
can only concentrate for compatibility with MSIE ver.6.0 and above.

Below is the code that I want to implement.

//
if (!window.event.ctrlKey) return true;
try {
switch(window.event.keyCode){
case 37: // left
window.event.keyCode = 9;
window.event.ctrlKey = false; // <-- this is the problem
break;
case 39: // right
window.event.keyCode = 9;
window.event.ctrlKey = false; // <-- this is the problem
window.event.shiftKey = true; // <-- this is also problem..
break;
}
return true;
}
catch(exception )
{
return false;
}

Thanks in advanced!

rgs,
hiroshi


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #4
On 04 Apr 2004 21:37:41 GMT, Hiroshi Ochi <hi**********@hotmail.com> wrote:
To enhanced usability, I would like to set the TAB behaviour if user
presses 'CTRL + Right Arrow' key and to set the SHIFT + TAB behaviour if
user presses 'CTRL + Left Arrow' key.

I especially need this function in HTML Tables. For the time being, I
can only concentrate for compatibility with MSIE ver.6.0 and above.


You could investigate something I touched on in my post: firing your own
event. Your code would basically be structured:

// e - is the current event (window.event)

var newEvent = document.createEventObject( e );

newEvent.keyCode = 9;
newEvent.ctrlKey = false; // this won't error :)

e.srcElement.fireEvent( 'eventName', newEvent );

'eventName' is probably 'onkeypress'. You should also be able to replace
'e.srcElement' with 'this'.

You might run into problems if you do decide to support browsers other
than IE. At present, the W3C have delayed, perhaps permanently, the
publication of the DOM 3 Events specification as a Recommendation. This
document was set to introduce keyboard events, which are currently missing
from the DOM 2 Events spec. Mozilla has implemented keyboard events from
DOM 3 Events, but they used an early version which has since changed
method and interface names.

Good luck,
Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #5
DU
Hiroshi Ochi wrote:
Thanks Michael and DU,

To enhanced usability,
People with disabilities or using special browsers (text-to-speech
synthetizing browser or braille browser or just MSIE with accessibility
features triggered with keyboard combos) might have problem using a page
with such reformating.

I would like to set the TAB behaviour if user presses 'CTRL + Right Arrow' key and to set the SHIFT + TAB behaviour if
user presses 'CTRL + Left Arrow' key.

If I understood you correctly, you want the user's browser to react like
if the user typed in <tab> if the user typed <Ctrl>+<right arrow> and
the user's browser to react like <Shift>+<tab> if the user typed
<Ctrl>+<left arrow>. You're asking to reformat 2 keyboard combination
shortcuts to act like 2 other ones, to duplicate 2 other ones.

Now, this could be doable in MSIE 6 for windows and in NS 7.x and
Mozilla-based browsers. It could be doable also with Opera 7.x; I'm less
sure about this one though. But I would really want to *first*
understand why you would want to reformat the key stroke combinations
(and duplicate the already working and well established functionality of
another key combo) and I sure would want to see first the page which
supposedly need such reformating and javascript coding.

DU
I especially need this function in HTML Tables. For the time being, I
can only concentrate for compatibility with MSIE ver.6.0 and above.

Below is the code that I want to implement.

//
if (!window.event.ctrlKey) return true;
try {
switch(window.event.keyCode){
case 37: // left
window.event.keyCode = 9;
window.event.ctrlKey = false; // <-- this is the problem
break;
case 39: // right
window.event.keyCode = 9;
window.event.ctrlKey = false; // <-- this is the problem
window.event.shiftKey = true; // <-- this is also problem..
break;
}
return true;
}
catch(exception )
{
return false;
}

Thanks in advanced!

rgs,
hiroshi


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 23 '05 #6
Thanks again Mike!

I tried your solution, and managed to change the value of ctrlKey
property. But now I realize that eventhough I can change the value of
ctrlKey and keyCode, it won't behave like tab key. Do you happen to know
why? Below is my sample code.

<script>
document.onkeydown=onkeydownArrowsHandler;

function onkeydownArrowsHandler(e) {
e = e||window.event;
var o = (e.srcElement||e.target);
//omit the following
if(!o) return true;
if(o.tagName != "TEXTAREA" && o.tagName != "INPUT" && o.tagName !=
"SELECT") return true;
// alert(e.keyCode);
// alert(e.ctrlKey);
// alert(e.shiftKey);
if(!e.ctrlKey) return true;
if(!(e.keyCode == 37 || e.keyCode == 39 )) return true;

//create event object
var newEvent = document.createEventObject(e);

newEvent.keyCode = 9;
newEvent.ctrlKey = false;

if(e.keyCode == 37) //if arrow left, shift + tab
newEvent.shiftKey = true;

o.fireEvent( 'onkeydown', newEvent );

return true;
}
</script>

Thanks,
hiroshi

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #7
Hello DU,

Thanks for your comment. Yes, I wish the behaviour something like
phpmyadmin tables.

To get the picture of what I am talking about, please access
http://www.phpmyadmin.net/phpMyAdmin/ and click PMA_bookmark table in
the left frame. Click 'Check All' to mark all checkbox, and in 'With
Selected:' click the 'Change' icon.

You will be directed to tbl_properties_structure.php page, and in the
table shown, try to press <ctrl> and arrow keys to move
up,down,right,left. I am expecting the behaviour to be like this.

In phpmyadmin, as you might know, their trick is to set the whole field
with id, and focus the cursor using the unique id (x and y axis) for
each field. In our application (we are creating a web-based sales-order
management) we can not use this idea because user can dynamically add or
delete a certain row, and according to user authorization, we
dynamically hide a certain column by setting the style to
'display:none'. And in some cases, we have nested tables or multiple
input in one <td> tag.

I did try to moving around by referencing the nextSibling or
previousSibling, but there are too many logic must be implemented
inside. Especially for the moving to left and right side. For up and
down, we can settle more or less 80% of the cases, but for left and
right, still far from complete. It is therefore the safest way to
'mimic' the behaviour of <tab> key for <ctrl>+<right arrow> and
<shift>+<tab> key for <ctrl>+<left arrow> key.

I understand your argument of why bother changing the behaviour of well
known key, but I also believe that if user can use <ctrl> key and arrow,
the behaviour is more consistent and more user friendly. What do you
think?

rgs,
hiroshi


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #8
On 06 Apr 2004 03:57:30 GMT, Hiroshi Ochi <hi**********@nospam.com> wrote:
I tried your solution, and managed to change the value of ctrlKey
property. But now I realize that eventhough I can change the value of
ctrlKey and keyCode, it won't behave like tab key. Do you happen to know
why? Below is my sample code.


[snip]

I tried various methods myself, and couldn't get IE to act on the
simulated events. It's strange because I was under the impression that the
whole point of faking an event was to get the UI to act as though the user
caused said event.

An alternative that I've been looking at involves the tree navigation,
using nextSibling and previousSibling, which you wanted to avoid. However,
you should be able to avoid the problems you encountered by making good
use of the tabindex attribute (tabIndex property) to ensure that elements
are traversed in the correct sequence, irrespective of the complexity of
underlying HTML. The idea involved walking the tree in its entirety
(unless only a particular area of the document is of interest), adding
controls to a multi-dimensional array, the initial elements being a
tabIndex. The current tabindex level and active control are recorded, to
that when the user navigates using your system, the next control can be
found. Monitoring changes made through other methods (tabbing and
clicking) complicates things a little, but it's still feasible. Certainly
not simple, though.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #9
On Wed, 14 Apr 2004 00:02:48 GMT, Michael Winter
<M.******@blueyonder.co.invalid> wrote:
On 06 Apr 2004 03:57:30 GMT, Hiroshi Ochi <hi**********@nospam.com> wrote:
I tried your solution, and managed to change the value of ctrlKey
property. But now I realize that eventhough I can change the value of
ctrlKey and keyCode, it won't behave like tab key. Do you happen to know
why? Below is my sample code.


[snip]

I tried various methods myself, and couldn't get IE to act on the
simulated events. It's strange because I was under the impression that the
whole point of faking an event was to get the UI to act as though the user
caused said event.


Remember simulated events can't trigger things in the application,
only in the page, tabkeys are being treated as application level
things presumably.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 23 '05 #10
Thanks always Mike,

I will try your tabIndex property idea.

Best Regards,
Hiroshi

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #11

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

Similar topics

1
by: Loony | last post by:
I want to use a ctrlKey event in my script! I have a code like this: function hiLite(imgDocID, imgObjName) { document.images.src = eval(imgObjName + ".src") } function KeyDown() {...
3
by: Johnny M | last post by:
using Access 2003 Pardon the subject line, but I don't have a better word for this strange behavior (or behavior I don't understand!!!) I have a class module named DepreciationFactor. One of...
7
by: MP | last post by:
Hello, I am trying to write a class that will expose some properties. One of the property is extracted from a SQL database and can be NULL or some integer value. Is there a elegant way of...
3
by: MattC | last post by:
Hi, I found this code somewhere on the net and need to make some alterations. public class GenericSorter : IComparer { String sortProperty; bool sortOrder; public GenericSorter(String...
2
by: Edward Diener | last post by:
How does one specify in a component that a property is a pointer to another component ? How is this different from a property that is actually an embedded component ? Finally how is one notified in...
0
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
2
by: niels.froehling | last post by:
Hy; I'm stucked in modifying events to make a multi-select select-input being additive/subtractive only. Because I should offer a solution similar to that select for DAUs (aka. MostIdioticUser)...
15
by: Lauren Wilson | last post by:
Owning your ideas: An essential tool for freedom By Daniel Son Thinking about going into business? Have an idea that you think will change the world? What if you were told that there was no way...
1
by: cday119 | last post by:
I have a Class with about 10 properties. All properties return right except for one. It is real annoying and I can't see why its not working. Maybe someone else can see something. It is the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.