Click to See Complete Forum and Search --> : Detecting the CTRL-Button


cubefarmer
06-05-2003, 03:48 AM
Hi,

i try to implement an application which uses the internet explorer as user interface. I need to somehow disable the use of ie-shortcuts (like CTRL-N for opening a new window) for this.

What i wanted to do is detect the buttons on the keypressed event and if the CTRL-Button is pressed i give an alert that the user should not use it. The Problem with this is: The right ALT-Button has the same number as the CTRL-Buttons and i cannot disable this ALT-Button, because i need it in the application.

Is there another possibility to detect only the CTRL-Button or to disable the shortcuts with javascript??

Thanks in advance for any help!

Cheers,
Thorsten

BrainDonor
06-05-2003, 11:18 AM
Try this. It works well for me.

// function called every time a key is pressed down
function checkKP()
{
if(event.ctrlKey)
if((event.keyCode == 78) || (event.keyCode == 104))
alert('CTRL-N function is unavailable')
event.returnValue = false;
}

Tom

brendandonhue
06-05-2003, 08:15 PM
Originally posted by Dave Clark
I've always heard the you can't prevent the browser from reacting to its shortcut keys.

Dave
From what I have tried...it executes the javascript code you specified, then the browser/OS still does its thing.

cubefarmer
06-06-2003, 10:07 AM
Thanks for the help, but it didn't work, sorry. Now i tried something different an got the strangest of results:

I put the following between the inkeydown() Event:
if (window.event.keyCode == 17) alert("STRG-TAste");
window.status = "Taste mit Dezimalwert " + window.event.keyCode + " gedrueckt";

If i open the page (which is generated through jsp, btw.) i get the alert when hitting the right ALT-Key and on both CTRL-Keys and the number in the statusline shows '17'.

If i omit the first line the alert doesn't come (obviously) and the number in the statusline shows a '18', when i hit either the right or left ALT-Key and '17' when i hit one of the CTRL-Keys.

Any ideas why??

Thorsten

brendandonhue
06-06-2003, 02:23 PM
I didnt test it but the proper syntax is

if (window.event.keyCode == 17) {alert("STRG-TAste");
window.status = "Taste mit Dezimalwert " + window.event.keyCode + " gedrueckt"};
Maybe that makes a difference.

BrainDonor
06-08-2003, 11:17 AM
I've only used this in IE6. It does work...just like I need it to. I'm only concerned with IE at this point as this is for my company's Intranet...and we only use IE.

Tom