I want to make some shortcut keys (example Alt+K) to do a "onclick" on a button. How can I do this?

Daniweb for example has that "Ctrl+B" makes the text bold.


Troy III commented: A correct answer has been given to you - you need to say "THANK YOU!" and mark your thread as "Solved!" -2

Recommended Answers

All 7 Replies

BTW, jQuery is also possible BUT alone; No additional jQuery libraries....

This page has a zip showing how to do it.

hai riahc3,

i think this code will help you (this code can handle the Alt + k combination key event)

<script language="JavaScript" type="text/javascript">
 var isAltPressed = false;
    if(e.which == 18) 

     if(e.which == 18) isAltPressed=true; 
     if(e.which == 75 && isAltPressed == true) { 
            alert(" Alt + k is pressed" ); // or do whatever you wnat
            //return false;  // incase if you click predefined shot cut key combination

let me know if you have any doubts

happy coding

you may use shortcut.js as pritaeas said

the following url gives the full description about handling combination/short cut of keys using java script


but its java script library

i dont know whether it is your exact solution or not

let me know if you have doubts

You guys found a loophole in my post....

OK: No Javascript libraries or jQuery libraries.

OK: No Javascript libraries

I didn't suggest to use that library as-is, but as a code sample on how to get it done.

I want to make some shortcut keys (example Alt+K) to do a "onclick" on a button. How can I do this?

isn't the: accesskey="K" attribute working for you?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.