-1

Hello

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.

Thanks

Votes + Comments
A correct answer has been given to you - you need to say "THANK YOU!" and mark your thread as "Solved!"
4
Contributors
7
Replies
21
Views
4 Years
Discussion Span
Last Post by Troy III
0

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

Edited by riahc3

0

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;
 document.onkeyup=function(e){   
    if(e.which == 18) 
       isAltPressed=false; 
 } 

 document.onkeydown=function(e){  
     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
     } 
}
</script>

let me know if you have any doubts

happy coding

Edited by radhakrishna.p: giving clarity on the solution

2

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

OK: No Javascript libraries or jQuery libraries.

1

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.

0

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?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.