最近在写项目时发现之前一直能用的键盘事件 keyCode 属性被 ts 规范提示说要被废弃了
    keyCode is deprecated - 图1

    于是便去寻找代替的方法,以 esc 事件为例 (上图 ESCAPE 为一个变量,值为 27),发现现在应该改为 (属性 keyCode => key , 对应值由 number 类型 => string 类型),写法为下图所示
    keyCode is deprecated - 图2

    下图是变量名对照表例如 MAC_ENTER 改为 MacEnter 即可 (没有全部试过不过应该都能用,希望能帮到刚好需要的人)

    1. export declare const MAC_ENTER = 3;
    2. export declare const BACKSPACE = 8;
    3. export declare const TAB = 9;
    4. export declare const NUM_CENTER = 12;
    5. export declare const ENTER = 13;
    6. export declare const SHIFT = 16;
    7. export declare const CONTROL = 17;
    8. export declare const ALT = 18;
    9. export declare const PAUSE = 19;
    10. export declare const CAPS_LOCK = 20;
    11. export declare const ESCAPE = 27;
    12. export declare const SPACE = 32;
    13. export declare const PAGE_UP = 33;
    14. export declare const PAGE_DOWN = 34;
    15. export declare const END = 35;
    16. export declare const HOME = 36;
    17. export declare const LEFT_ARROW = 37;
    18. export declare const UP_ARROW = 38;
    19. export declare const RIGHT_ARROW = 39;
    20. export declare const DOWN_ARROW = 40;
    21. export declare const PLUS_SIGN = 43;
    22. export declare const PRINT_SCREEN = 44;
    23. export declare const INSERT = 45;
    24. export declare const DELETE = 46;
    25. export declare const ZERO = 48;
    26. export declare const ONE = 49;
    27. export declare const TWO = 50;
    28. export declare const THREE = 51;
    29. export declare const FOUR = 52;
    30. export declare const FIVE = 53;
    31. export declare const SIX = 54;
    32. export declare const SEVEN = 55;
    33. export declare const EIGHT = 56;
    34. export declare const NINE = 57;
    35. export declare const FF_SEMICOLON = 59;
    36. export declare const FF_EQUALS = 61;
    37. export declare const QUESTION_MARK = 63;
    38. export declare const AT_SIGN = 64;
    39. export declare const A = 65;
    40. export declare const B = 66;
    41. export declare const C = 67;
    42. export declare const D = 68;
    43. export declare const E = 69;
    44. export declare const F = 70;
    45. export declare const G = 71;
    46. export declare const H = 72;
    47. export declare const I = 73;
    48. export declare const J = 74;
    49. export declare const K = 75;
    50. export declare const L = 76;
    51. export declare const M = 77;
    52. export declare const N = 78;
    53. export declare const O = 79;
    54. export declare const P = 80;
    55. export declare const Q = 81;
    56. export declare const R = 82;
    57. export declare const S = 83;
    58. export declare const T = 84;
    59. export declare const U = 85;
    60. export declare const V = 86;
    61. export declare const W = 87;
    62. export declare const X = 88;
    63. export declare const Y = 89;
    64. export declare const Z = 90;
    65. export declare const META = 91;
    66. export declare const MAC_WK_CMD_LEFT = 91;
    67. export declare const MAC_WK_CMD_RIGHT = 93;
    68. export declare const CONTEXT_MENU = 93;
    69. export declare const NUMPAD_ZERO = 96;
    70. export declare const NUMPAD_ONE = 97;
    71. export declare const NUMPAD_TWO = 98;
    72. export declare const NUMPAD_THREE = 99;
    73. export declare const NUMPAD_FOUR = 100;
    74. export declare const NUMPAD_FIVE = 101;
    75. export declare const NUMPAD_SIX = 102;
    76. export declare const NUMPAD_SEVEN = 103;
    77. export declare const NUMPAD_EIGHT = 104;
    78. export declare const NUMPAD_NINE = 105;
    79. export declare const NUMPAD_MULTIPLY = 106;
    80. export declare const NUMPAD_PLUS = 107;
    81. export declare const NUMPAD_MINUS = 109;
    82. export declare const NUMPAD_PERIOD = 110;
    83. export declare const NUMPAD_DIVIDE = 111;
    84. export declare const F1 = 112;
    85. export declare const F2 = 113;
    86. export declare const F3 = 114;
    87. export declare const F4 = 115;
    88. export declare const F5 = 116;
    89. export declare const F6 = 117;
    90. export declare const F7 = 118;
    91. export declare const F8 = 119;
    92. export declare const F9 = 120;
    93. export declare const F10 = 121;
    94. export declare const F11 = 122;
    95. export declare const F12 = 123;
    96. export declare const NUM_LOCK = 144;
    97. export declare const SCROLL_LOCK = 145;
    98. export declare const FIRST_MEDIA = 166;
    99. export declare const FF_MINUS = 173;
    100. export declare const MUTE = 173;
    101. export declare const VOLUME_DOWN = 174;
    102. export declare const VOLUME_UP = 175;
    103. export declare const FF_MUTE = 181;
    104. export declare const FF_VOLUME_DOWN = 182;
    105. export declare const LAST_MEDIA = 183;
    106. export declare const FF_VOLUME_UP = 183;
    107. export declare const SEMICOLON = 186;
    108. export declare const EQUALS = 187;
    109. export declare const COMMA = 188;
    110. export declare const DASH = 189;
    111. export declare const SLASH = 191;
    112. export declare const APOSTROPHE = 192;
    113. export declare const TILDE = 192;
    114. export declare const OPEN_SQUARE_BRACKET = 219;
    115. export declare const BACKSLASH = 220;
    116. export declare const CLOSE_SQUARE_BRACKET = 221;
    117. export declare const SINGLE_QUOTE = 222;
    118. export declare const MAC_META = 224;

    https://blog.csdn.net/smallNut/article/details/106972220