From: JR on
On Dec 11, 8:40 am, Krist <krisl...(a)gmail.com> wrote:
> Hi All,
>
> In our web application we want to disable user from pressing CTRL key.
> and we want to implement this for IE, Firefox and if possible other
> browser.
>
> I have tried this code, doesn't work :
>
> <script type="text/javascript">
> document.onkeyup = KeyCheck;
> function KeyCheck()
> {
>    var KeyID = (window.event) ? event.keyCode : e.keyCode;
>    if ( KeyID  == 17) {
>         alert("Test Alert System");
>    }}
>
> </script>
>
> Pls help me to fix the code...
>
> Thank you very much,
> Krist

Use document.onkeydown and the code below:

<script type="text/javascript">
document.onkeydown = keyCheck;
function keyCheck(e) {
e = e || window.event;
if (e.ctrlKey) {
alert("CTRL key is not allowed");
}
}
</script>

Cheers,
JR
From: Krist on
On 12 Des, 03:21, JR <groups_j...(a)yahoo.com.br> wrote:
> On Dec 11, 8:40 am, Krist <krisl...(a)gmail.com> wrote:
>
>
>
>
>
> > Hi All,
>
> > In our web application we want to disable user from pressing CTRL key.
> > and we want to implement this for IE, Firefox and if possible other
> > browser.
>
> > I have tried this code, doesn't work :
>
> > <script type="text/javascript">
> > document.onkeyup = KeyCheck;
> > function KeyCheck()
> > {
> >    var KeyID = (window.event) ? event.keyCode : e.keyCode;
> >    if ( KeyID  == 17) {
> >         alert("Test Alert System");
> >    }}
>
> > </script>
>
> > Pls help me to fix the code...
>
> > Thank you very much,
> > Krist
>
> Use document.onkeydown and the code below:
>
> <script type="text/javascript">
>   document.onkeydown = keyCheck;
>   function keyCheck(e) {
>     e = e || window.event;
>     if (e.ctrlKey) {
>       alert("CTRL key is not allowed");
>     }
>   }
> </script>
>
> Cheers,
> JR- Sembunyikan teks kutipan -
>
> - Perlihatkan teks kutipan -

Thanks JR,
That is what I need.

God bless you
From: Thomas 'PointedEars' Lahn on
Krist wrote:

> On 12 Des, 03:21, JR <groups_j...(a)yahoo.com.br> wrote:
>> document.onkeydown = keyCheck;

Responsible developers feature-test host object's properties instead, and
use this only as a fallback for the standards-compliant approach.

>> function keyCheck(e) {

Reasonable people use a function expression here instead.

>> e = e || window.event;

Reasonable people use an `if' statement here instead.

>> if (e.ctrlKey) {

Responsible developers feature-test host object's properties before they are
accessing them in a type-converting test. Then again, responsible
developers would not try this whole nonsense in the first place.

>> alert("CTRL key is not allowed");

window.alert(...);

but neither should not be used here.

>> }
>> }
>> </script>
>>
>> Cheers,
>> [...]
>
> Thanks JR,
> That is what I need.

No, what you *need* is a dosage of common sense. Leave *my* keyboard alone!

> God bless you

Said the blind led by the blind.


PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7(a)news.demon.co.uk> (2004)
From: Austin Matzko on
On Dec 11, 9:05 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de>
wrote:
> >> e = e || window.event;
>
> Reasonable people use an `if' statement here instead.

Would you please elaborate? I'm curious why an "if" statement would
be better.

The statement "e = e || window.event" appears in a
comp.lang.javascript FAQ example: <http://www.jibbering.com/faq/
#FAQ4_26>
From: Stefan Weiss on
On 12/12/09 04:05, Thomas 'PointedEars' Lahn wrote:
> Then again, responsible developers would not try this whole nonsense in the first place.
....
> No, what you *need* is a dosage of common sense. Leave *my* keyboard alone!

Exactly! Thank you, that needed to be said.

I use Ctrl a *lot*. I use it to operate my browser, to scroll the page,
to copy and paste text, etc. If I saw a site where ctrl triggered a
JavaScript alert, I would automatically mentally file it as evil / scum
/ target for abuse. At the very least, I'd add it to my list of blocked
sites. If I'm bored I might have a look around and see what else looked
broken. It's not very clever to annoy your guests.

Even if this was intended strictly for an in-house application, I'd like
to hear the rationale for the OP's request.


stefan