Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 27048 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > JavaScript > Fire Keys in Java Script ...
Santosh4u

Fire Keys in Java Script

 Code Snippet posted by: Santosh4u | Posted on: 10/26/2009 | Category: JavaScript Codes | Views: 1319 | Status: [Member] | Alert Moderator   
Ads

Description:
Just Drag a Text Box and Focus the Curser inside the Textbox.
Then Press the Combined Key.
<html>

<head>
<script language="JavaScript">
function CtrlKeys(e)
{
//Create an array
var arrCtrlKeys = new Array('a', 'n', 'c', 'x', 'v', 'j');
var key;
var isCtrl;

if(window.event)
{
key = window.event.keyCode;
if(window.event.ctrlKey)
isCtrl = true;
else
isCtrl = false;
}

else
{
key = e.which;
if(e.ctrlKey)
isCtrl = true;
else
isCtrl = false;
}


//if ctrl is pressed check if other key is in forbidenKeys array
if(isCtrl)
{
for(i=0; i<arrCtrlKeys .length; i++)
{
//case-insensitive comparation
if(arrCtrlKeys.toLowerCase() == String.fromCharCode(key).toLowerCase())
{
alert('You have pressed CTRL + '
+String.fromCharCode(key)
+'.');

return false;
}
}
}
return true;
}
</script>

</head>
<body>
<form method="">
<div>
<h3>Test Key Combinition [Ctrl+A, Ctrl+N, Ctrl+C, Ctrl+X, Ctrl+V,Ctrl+J]</h3>
<input type="text" name="mytext"
onKeyPress="return CtrlKeys(event);"
onKeyDown="return CtrlKeys(event);" />
</div>
</body>
</html>

Regards
Santosh
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 6/19/2013 6:22:25 AM