Hi! I'm working on a graphics interface that is almost completely JavaScript. I want to assign a key combination to a function. For example: if the user hits Control+T, a new window would pop open.

Any tips?

Thanks!

Tom Tolleson

That seems to work for when the user presses any key. What I'm going for is a specific event that is a combination of the CTRL key with the letter T.

Here's what I have so far:

function doSomething() {
 // The function code goes here
}



event.ctrlKey("t") {
	doSomething;
}

I'm just not sure how to express the combination of the CTRL press and the letter T press together.

Thanks!

Hi
evenif u will acheive this you will have problem, coz browser will also do some function in this case, like Mozilla will start new tab.
so try some thing else.
Why you want to do this, probably we can suggest some thing different.

Thanks for the reply.

I'm making this for an internal website (intranet) and it only needs to work in Internet Explorer.

I want the user to be able to pull up a pop-up window in which to write. But I cannot have a button on the webpage to activate it. I have to follow a strict design guideline.

Thanks again!

it only needs to work in Internet Explorer.

it has solve your problem,
when you will press ctrl+t(or any other combination) it will return you perticular keyCode using which you can identify the key combination.
in IE you can capture keyCode using window.event.keyCode
use document.onkeypress to capture keypress event on whole document.
see this also.
hope this will solve your problem.

following example may help you:

<html>
<head>
<script type="text/javascript">
document.onkeypress=function()
{
	
	alert(window.event.keyCode);
	 
}
</script>
</head>
</body>
this example will work in IE 6
</body>
</html>

Hey! Thanks for the tip!

The following code does the trick:

document.onkeypress=function(){
    if (window.event.keyCode == 20) {
       alert('It Works!');
       }
}

Thanks again!

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.