467,877 Members | 1,243 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

keycode for ctrl ??

How do I capture the ctrl keypress?

Is it possible for js to intercept the ctrl-n combination and prevent
the creation of a new IE window??

(Have 3 huge books on js and none of them mention this subject)
Oeyvind

--
http://home.online.no/~oeyvtoft/ToftWeb/
http://home.online.no/~oeyvtoft/Toft...rameset/3d.htm
http://home.online.no/~oeyvtoft/Toft...eset/flash.htm


Jul 20 '05 #1
  • viewed: 30876
Share:
8 Replies
oeyvind toft wrote on 22 aug 2003 in comp.lang.javascript:
How do I capture the ctrl keypress?

Is it possible for js to intercept the ctrl-n combination and prevent
the creation of a new IE window??

(Have 3 huge books on js and none of them mention this subject)


<body
oncontextmenu="if(event.ctrlKey){alert('ctrl-rightclicked');return false}">
<input onkeydown="if(event.keyCode==17)alert('ctrl key pressed')">

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #2
"oeyvind toft" <oe******@online.no> writes:
How do I capture the ctrl keypress?
You probably want the ctrl keydown, not keypress.

Make any keydown event handler, even
document.onkeydown = function(event){
event = event || window.event; //IE suckes
if ( event.keyCode == 17 ) {
// ctrl pressed
}
}
Is it possible for js to intercept the ctrl-n combination and prevent
the creation of a new IE window??
That depends on the browser, where the focus is, and the phase of the
moon. That is, not always. (Well, you do say IE window, so I assume
you are mostly interested in IE).

This might work in some browsers, including IE6.
document.onkeydown = function(e) {
e=e||window.event;
if (e.keyCode == 78) {
return false;
}
}

The more relevant question is: Why would you think you needed
to do this? Because I am pretty certain that you don't. After all,
you can still open new windows in many other ways.
(Have 3 huge books on js and none of them mention this subject)


Good books, then. They shouldn't tell you how to interfere with the
users' keyboard shortcuts. They are there for a reason, you know.

Sometimes I wish I had a blacklist, just like my bookmarks. If I
blacklist a page, my browser will never send me back to it without
a warning. Then I could blacklist pages that interfered with my
keyboard.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3
Lasse Reichstein Nielsen <lr*@hotpop.com> writes:
if (e.keyCode == 78) {


Oops. Change this to
if (e.keyCode == 78 && e.ctrlKey) {
unless you want to turn off the n key completely.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4
"oeyvind toft" <oe******@online.no> writes:
The reason for blocking ctrl-n is this:

A Flash educational movie embedded in IE is supposed to simulate
various software. The user should be able to use ctrl-n and have it
passed to Flash, at the same time prevent opening another IE window.
They should look into embedding the Flash in an HTML application instead
of a normal browser window. Then most of these problems goes away.
<URL:http://msdn.microsoft.com/workshop/author/hta/overview/htaoverview.asp>
I didnt mean the books lacks info on interfering with user`s
shortcuts, I meant I couldnt find the keycodes themselves.


Bad books, then :)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
Thanks again Lasse...

Yup, bad books allright...I cant even find key/keyCode anywhere in the
indicies.

hta looks interesting and I`ll forward the link to my "client".

Oeyvind

--
http://home.online.no/~oeyvtoft/ToftWeb/
http://home.online.no/~oeyvtoft/Toft...rameset/3d.htm
http://home.online.no/~oeyvtoft/Toft...eset/flash.htm

"Lasse Reichstein Nielsen" <lr*@hotpop.com> skrev i melding
news:br**********@hotpop.com...
"oeyvind toft" <oe******@online.no> writes:
The reason for blocking ctrl-n is this:

A Flash educational movie embedded in IE is supposed to simulate
various software. The user should be able to use ctrl-n and have it
passed to Flash, at the same time prevent opening another IE window.
They should look into embedding the Flash in an HTML application instead
of a normal browser window. Then most of these problems goes away.

<URL:http://msdn.microsoft.com/workshop/author/hta/overview/htaoverview.asp>
I didnt mean the books lacks info on interfering with user`s
shortcuts, I meant I couldnt find the keycodes themselves.


Bad books, then :)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #6
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:br**********@hotpop.com...
<snip>
I didnt mean the books lacks info on interfering with user`s
shortcuts, I meant I couldnt find the keycodes themselves.


Bad books, then :)


I am not so sure. Are keycodes universal or might they be expected to
vary with OS, keyboard layout, local language, etc? Mozilla key events
have a battery of numeric properties such as:-

DOM_VK_CANCEL == 3
DOM_VK_CAPS_LOCK == 20
DOM_VK_CLEAR == 12
DOM_VK_CLOSE_BRACKET == 221
DOM_VK_COMMA == 188
DOM_VK_CONTROL == 17
DOM_VK_D == 68
DOM_VK_DECIMAL == 110
DOM_VK_DELETE == 46
DOM_VK_DIVIDE == 111
DOM_VK_DOWN == 40

- that look like constants (all uppercase, underline separated
identifiers (example values from Window OS/UK English keyboard)) mapping
keys to codes. I imagine that Mozilla would refer to the named property
when making decisions about keyboard input, allowing the number assigned
to vary with the OS (and/or whatever else was relevant).

Richard.
Jul 20 '05 #7
Thanks again for input guys...
Appreciate it =O)

Oeyvind

--
http://home.online.no/~oeyvtoft/ToftWeb/
http://home.online.no/~oeyvtoft/Toft...rameset/3d.htm
http://home.online.no/~oeyvtoft/Toft...eset/flash.htm

"Lasse Reichstein Nielsen" <lr*@hotpop.com> skrev i melding
news:br**********@hotpop.com...
"oeyvind toft" <oe******@online.no> writes:
The reason for blocking ctrl-n is this:

A Flash educational movie embedded in IE is supposed to simulate
various software. The user should be able to use ctrl-n and have it
passed to Flash, at the same time prevent opening another IE window.
They should look into embedding the Flash in an HTML application instead
of a normal browser window. Then most of these problems goes away.

<URL:http://msdn.microsoft.com/workshop/author/hta/overview/htaoverview.asp>
I didnt mean the books lacks info on interfering with user`s
shortcuts, I meant I couldnt find the keycodes themselves.


Bad books, then :)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #8
"Richard Cornford" <Ri*****@litotes.demon.co.uk> writes:
Are keycodes universal or might they be expected to vary with OS,
keyboard layout, local language, etc?


They vary.
Some are mostly standardized. The normal letter and digit keys are
represented by the ASCII value of the letter or digit. Even for these
there are differences.

In IE6, Opera 7.2 and Mozilla FB 0.6, pressing "a" and "shift+a" both
give the keyCode 65 (capital A).

In Netscape 4, pressing "a" gives 97, but "shift+a" gives 65.

Opera 7.2 (still in beta) changed the keycodes of some keys (e.g.,
cursor keys) to be compatible with IE. Earlier ones weren't.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Perttu Pulkkinen | last post: by
6 posts views Thread by Justin Beasley | last post: by
6 posts views Thread by rich_poppleton | last post: by
4 posts views Thread by Thomas Christensen | last post: by
2 posts views Thread by Alberto | last post: by
1 post views Thread by Peter Anthony | last post: by
1 post views Thread by kkm | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.