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

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

This page has a zip showing how to do it.

Jump to Post

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.

Jump to Post

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;
 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

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

http://www.openjs.com/scripts/events/keyboard_shortcuts/

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 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.