Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've two buttons called cancel and login in a web page, if i use keyboard shortcut key the button will trigger

i want to use alt + c for clear button and

alt + l for login button.

is there any solution means reply me..



thanks in advance...
Posted
Updated 2-Mar-12 1:13am
v2

Refer similar question on CP
Short cut keys in asp.net[^]
or may be try this
JavaScript
var isCtrl = false;
document.attachEvent('onkeyup', KeyUpHandler);
document.attachEvent('onkeydown', KeyDownHandler);

function KeyUpHandler()
{
if (event.keyCode == 17)
{
isCtrl=false;
}
}

function KeyDownHandler()
{
if (event.keyCode == 17)
{
isCtrl=true;
}
if (event.keyCode == 83 && isCtrl == true)
{
' call button save click event document.getElementById(btnSave).click();
}
else if (event.keyCode == 67 && isCtrl == true)
{
' call button close click event document.getElementById(btnClose).click();
}
}
 
Share this answer
 
Comments
thatraja 2-Mar-12 10:22am    
Right, 5!
Anuja Pawar Indore 5-Mar-12 0:34am    
Thanks Raja
try this

C#
if (window.captureEvents) {
    window.captureEvents(Event.KeyUp);
    window.onkeyup = executeCode;
}
else if (window.attachEvent) {
    document.attachEvent('onkeyup', executeCode);
}

function executeCode(evt) {
    if (evt == null) {
        evt = window.event;
    }
    var theKey = parseInt(evt.keyCode, 10);
    switch (theKey) {
        case 113:  // F2
            document.getElementById('buttonid').click();
            break;
        case 119:  // F8
            document.getElementById('buttonid').click();
            break;
        case 120:  // F9
            document.getElementById('buttonid').click();
            break;
        case 87: //w
            if (window.event.altKey)
                document.getElementById('buttonid').click();
            break;
    }
    evt.returnValue = false;
    return false;
}
 
Share this answer
 
use Accesskey value of Button

Access key="s" mean alt+s

Accesskey="l" mean alt+l
 
Share this answer
 
Comments
CHill60 24-Apr-15 12:48pm    
Normally answering old questions will attract downvotes - but you're getting a 5 from me as I think this is the best answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900