首页 > 解决方案 > How to find Virtual key Code of keys i.e 0x41

问题描述

Is there a way to find the Virtual key Value of a key with javascript that will return eg-"0x41" instead of "65" ("A") for characters? I have tried .keyup(e) but it gives me "65" instead of "0x41". Would anyone know what could be done?

标签: javascript

解决方案


Javascript has a built in library for this conversion of hex/dec; check it out.

const dectohex = (decimalnum) => decimalnum.toString(16);
const hextodec = (hexnum) => parseInt(hexnum, 16);

console.log(dectohex(65));

推荐阅读