473,387 Members | 1,745 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,387 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 31270
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. }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...

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.