Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to add shortcut key for my grid. How to assign for new Alt+a.

What is the ascii key for Alt+a

Thanks
Basit

What I have tried:

I tried function key F1 as 112 ascii code.
Posted
Updated 26-Jun-16 9:15am
Comments
Afzaal Ahmad Zeeshan 26-Jun-16 15:03pm    
Add an event to keydown to the HTML body itself.

1 solution

ALT + A has no ASCII code (but the keyCode is 18), only A has an ASCII code and you will be testing against that one only. However, you will also be testing if the ALT key is also pressed by the user.

I would recommend attaching an event handler to the HTML document (or in a much recommended way, to the body element) and then handle it using JavaScript. So, for that just try this:
JavaScript
$(document).ready(function () {
    $('body').keydown(function () {
        if(window.event.altKey == true && window.event.keyCode == 65) {
            document.getElementById("landing").innerText = "Alt + A pressed.";
        } else {
            document.getElementById("landing").innerText = "Alt + A combination not made.";
        }
    });
});

This can also be tested at, Edit fiddle - JSFiddle[^]. You can now also add more combinations for the keys as per they are needed.

For more: KeyboardEvent Value (keyCodes, metaKey, etc) | CSS-Tricks[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Jun-16 16:36pm    
5ed.
—SA
Afzaal Ahmad Zeeshan 26-Jun-16 17:47pm    
Thank you, maybe you forgot to click on the stars. :-)
Sergey Alexandrovich Kryukov 26-Jun-16 18:01pm    
It happens, sorry; please don't hesitate to remind. Voted.
—SA
Afzaal Ahmad Zeeshan 26-Jun-16 19:03pm    
No problem, thank you. :-)
Ehsan Sajjad 31-Jul-16 8:00am    
well explained, upvoted :)

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