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

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
8 31250
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Perttu Pulkkinen | last post by:
I have different functions that receive window.event as parameter. Functions are used like this: <input type="text" id="x" onkeypress="return onKeyCurrencyCheck(ev, 'x')" onblur...
6
by: Justin Beasley | last post by:
Here is an answer for those who are looking for a keystroke evaluation script that works in Internet Explorer (IE 5.5, 6.0, 7.0 for PC--IE 4.0, 5.2 for Mac), Mozilla Firefox (Windows, Linux, and...
6
by: rich_poppleton | last post by:
Help.... I've got a textarea where people type in a description. However for certain reasons we need to stop them typing !$*^ . I have a solution this which works fine in IE: function...
4
by: Thomas Christensen | last post by:
I'm trying to figure out what key the user pressed using a Danish keyboard layout. charCodeAt returns the correct number, but event.keyCode returns a wrong number, when using one of the keys that...
2
by: Alberto | last post by:
Could you tell me witch is the difference between keycode, keyvalue and keydata in a keydown event? keyvalue is always the ascii code? thank you
3
by: Pugi! | last post by:
I got this (piece of) script from 'DHTML Utopia - Modern Webdesign - Using Javascript & DOM'. function aKeyWasPressed(e) { if (window.event) { var key = window.event.keyCode; } else { var key...
1
by: Peter Anthony | last post by:
This is a perfect example of how some information slips through the crack in MSDN2. There is NO explanation of what KeyValue is in MSDN2!! Sure, it has a page on it, here it is: ...
1
by: kkm | last post by:
hello everybody, look first source code. <script type="text/javascript"> .... .... if(keycode == h) { send to CTRL+F //FF searchbox window bottom. }
1
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...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.