<code
class
=
"js"
>document.addEventListener(
'keydown'
, e => console.log(
'altKey : '
+ e.altKey +
'\n'
+
'charCode (Deprecated) : '
+ e.charCode +
'\n'
+
'code : '
+ e.code +
'\n'
+
'ctrlKey : '
+ e.ctrlKey +
'\n'
+
'isComposing : '
+ e.isComposing +
'\n'
+
'key : '
+ e.key +
'\n'
+
'keyCode (Deprecated) : '
+ e.keyCode +
'\n'
+
'location : '
+ e.location +
'\n'
+
'metaKey : '
+ e.metaKey +
'\n'
+
'repeat : '
+ e.repeat +
'\n'
+
'shiftKey : '
+ e.shiftKey +
'\n'
+
'which (Deprecated) : '
+ e.which +
'\n'
+
'isTrusted : '
+ e.isTrusted +
'\n'
+
'type : '
+ e.type
));
const
Podium = {};
Podium.keydown =
function
(k) {
const
oEvent = document.createEvent(
'KeyboardEvent'
);
Object.defineProperty(
oEvent,
'keyCode'
,
{
get :
function
() {
return
this.keyCodeVal;
}
}
);
Object.defineProperty(
oEvent,
'which'
,
{
get :
function
() {
return
this.keyCodeVal;
}
}
);
if
(oEvent.initKeyboardEvent) {
oEvent.initKeyboardEvent(
"keydown"
, true, true, document.defaultView,
false, false, false, false, k, k);
}
else
{
oEvent.initKeyEvent(
"keydown"
, true, true, document.defaultView,
false, false, false, false, k, 0);
}
oEvent.keyCodeVal = k;
if
(oEvent.keyCode !== k) {
alert(
"keyCode mismatch "
+ oEvent.keyCode +
"("
+ oEvent.which +
")"
);
}
document.dispatchEvent(oEvent);
}
Podium.keydown(65);</code>