...

View Full Version : How to detect Ctrl key pressed?



skl
09-23-2005, 03:19 PM
Hi,

I have no problem in detecting the CTRL key with the javascript code event.keyCode or event.ctrlKey call in my script function. But once I called the setInterval() (e.g. <body onLoad='setInterval("poll()", 1000)'>) then the event is always "null". Please help.

Note: poll() is my javascript method where I would like to detect the CTRL key pressed.

Best Regards
skl

TNO
09-23-2005, 03:56 PM
Have you tried the following?


onkeydown="if (event.keyCode == 17){blah blah}"

skl
09-23-2005, 04:27 PM
Yes, it work as:

<body onkeydown='if (event.keyCode == 17){window.status="Blah Blah"}' onLoad="startPolling()"> ... </body>

But, the problem I am having is I have to check the keyCode in my javascript functions and do not know how to do it, for example:

function startPolling()
{
setInterval("poll()", 1000)
}
function poll()
{
window.status = event.ctrlKey; // or event.keycode
...
}

BTW, I do not use FORM in my page.

Best Regards,
skl

TNO
09-24-2005, 06:49 PM
Maybe something like this:

<script language="javascript">
function handleKeyDown(evt){
if(evt.keyCode==17){
---DoThis---
}
if(evt.keyCode==24){
---DoThat---
}

}
</script>

<body onkeydown="handleKeyDown(window.event);">

skl
09-27-2005, 07:05 PM
It works, thanks a lot.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum