Search code examples
javascriptdom-eventsasciiextended-ascii

ASCII code generation for the combination of keys


I want to know how to get the ASCII code for the combination of keys. Like I want to handle event for some unique key combination [alt+ctrl+shift].

Alternatively can you please tell me the ASCII code for [alt+Enter], [ctrl+Enter].


Solution

  • There are flags on the event object that tell you if the alt, control or shift keys have been entered:

    if (event.shiftKey) {}
    if (event.altKey) {}
    if (event.ctrlKey) {}
    

    To get the key code (e.g. space), you need to check the event.keycode (13 will get you enter)

    if (event.keyCode === 13){}