This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Capture multiple Key Press ctrl+p? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Capture multiple Key Press ctrl+p?" Watch "Capture multiple Key Press ctrl+p?" New topic
Author

Capture multiple Key Press ctrl+p?

chsanthosh kumar
Ranch Hand

Joined: Jun 28, 2005
Posts: 56
In My Intranet Application ,

I'm change the controls for media player, where i'm using the

combination like ctrl+p,ctrl+m and etc.

<script type="text/javascript">

function displayKeyCode(evt)
{
var textBox = getObject('txtChar');
var charCode = (evt.which) ? evt.which : event.keyCode
textBox.value = String.fromCharCode(charCode);
if (charCode == 18){
textBox.value = "Alt"; // F4
alert("You Pressed Alt");
}
if (charCode == 17 && charCode == 80)
{
textBox.value = "Ctrl+P"; // F7
alert("You Pressed Ctrl+P");
}
if (charCode == 17 && charCode == 79)
{
textBox.value = "Ctrl+O"; // F7
alert("You Pressed Ctrl+O");
}

if (charCode == 17 && charCode == 78)
{
textBox.value = "Ctrl+N"; // F7
alert("You Pressed Ctrl+N");
}

if (charCode == 17 && charCode == 77)
{
textBox.value = "Ctrl+M"; // F7
alert("You Pressed Ctrl+M");
}
var lblCharCode = getObject('spnCode');
lblCharCode.innerHTML = 'KeyCode: ' + charCode;
return false;
}
function getObject(obj)
{
var theObj;
if (document.all) {
if (typeof obj=='string') {
return document.all(obj);
} else {
return obj.style;
}
}
if (document.getElementById) {
if (typeof obj=='string') {
return document.getElementById(obj);
} else {
return obj.style;
}
}
return null;
}

</SCRIPT>


I used the above script to capture the keypress events but it is working for
only one Like (any Key), If clicked multiple keys but it is not captuing ,

i think some problem with my code,

please help me..


---------------------<br />SCJP(1.4)With 95%<br /> <br />Do it Right and Forget it!
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
you need to look into modifier key

Also be careful or you wll have people printing out your page!

Eric
chsanthosh kumar
Ranch Hand

Joined: Jun 28, 2005
Posts: 56
I got the solution,

Here is the Code

Thank You For helping Me.
Eric
[ December 27, 2006: Message edited by: chsanthosh kumar ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Capture multiple Key Press ctrl+p?
 
Similar Threads
How to disable ALT+F, ALT+E
Object properties.
Editing DIV
cross-browser javascript
how to create small windows