954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Ctrl+t?

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

Tom Tolleson
Light Poster
39 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 
DangerDev
Posting Pro in Training
485 posts since Jan 2008
Reputation Points: 165
Solved Threads: 59
 

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!

Tom Tolleson
Light Poster
39 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

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.

DangerDev
Posting Pro in Training
485 posts since Jan 2008
Reputation Points: 165
Solved Threads: 59
 

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!

Tom Tolleson
Light Poster
39 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 
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 perticularkeyCode 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>
DangerDev
Posting Pro in Training
485 posts since Jan 2008
Reputation Points: 165
Solved Threads: 59
 

Hey! Thanks for the tip!

The following code does the trick:

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

Thanks again!

Tom Tolleson
Light Poster
39 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

good i knew that, but i wanted you to try...any way nice job

DangerDev
Posting Pro in Training
485 posts since Jan 2008
Reputation Points: 165
Solved Threads: 59
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You