469,923 Members | 1,199 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

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 3189
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Loony | last post: by
2 posts views Thread by Edward Diener | last post: by
2 posts views Thread by niels.froehling | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.