kcc 1.0.0 • Public • Published 7 years ago Key Code Code
Key Code Code lets you map key codes to codes in JavaScript.
import keyCode from ' kcc ' ;
document . addEventListener (
' keypress ' ,
( event ) => {
if ( event . keyCode === keyCode . Space || event . keyCode === keyCode . Enter ) {
const target = event . target . closest ( ' [role=button]:not(button) ' ) ;
if ( target ) {
event . preventDefault ( ) ;
event . target . dispatchEvent (
new MouseEvent (
' click ' ,
{
bubbles : true ,
cancelable : true ,
view : target . ownerDocument . defaultView
}
)
) ;
}
}
}
) ;
When compiled as a JavaScript module using something like rollup , Key Code Code realistically contributes about 1 byte for each character you use from the library.
Versions Current Tags Version
Downloads (Last 7 Days) 1.0.0
1
Version History Version
Downloads (Last 7 Days) 1.0.0
1
Package Sidebar Install Downloads Weekly Downloads