<legend id='I2Vg3'><style id='I2Vg3'><dir id='I2Vg3'><q id='I2Vg3'></q></dir></style></legend>
  • <small id='I2Vg3'></small><noframes id='I2Vg3'>

    <tfoot id='I2Vg3'></tfoot>
        <bdo id='I2Vg3'></bdo><ul id='I2Vg3'></ul>

      1. <i id='I2Vg3'><tr id='I2Vg3'><dt id='I2Vg3'><q id='I2Vg3'><span id='I2Vg3'><b id='I2Vg3'><form id='I2Vg3'><ins id='I2Vg3'></ins><ul id='I2Vg3'></ul><sub id='I2Vg3'></sub></form><legend id='I2Vg3'></legend><bdo id='I2Vg3'><pre id='I2Vg3'><center id='I2Vg3'></center></pre></bdo></b><th id='I2Vg3'></th></span></q></dt></tr></i><div id='I2Vg3'><tfoot id='I2Vg3'></tfoot><dl id='I2Vg3'><fieldset id='I2Vg3'></fieldset></dl></div>
      2. 使用 shift 修饰符从键码中获取键字符(值)

        时间:2023-08-07
        <legend id='UvZBI'><style id='UvZBI'><dir id='UvZBI'><q id='UvZBI'></q></dir></style></legend>
        <i id='UvZBI'><tr id='UvZBI'><dt id='UvZBI'><q id='UvZBI'><span id='UvZBI'><b id='UvZBI'><form id='UvZBI'><ins id='UvZBI'></ins><ul id='UvZBI'></ul><sub id='UvZBI'></sub></form><legend id='UvZBI'></legend><bdo id='UvZBI'><pre id='UvZBI'><center id='UvZBI'></center></pre></bdo></b><th id='UvZBI'></th></span></q></dt></tr></i><div id='UvZBI'><tfoot id='UvZBI'></tfoot><dl id='UvZBI'><fieldset id='UvZBI'></fieldset></dl></div>
          <bdo id='UvZBI'></bdo><ul id='UvZBI'></ul>

            • <tfoot id='UvZBI'></tfoot>
                  <tbody id='UvZBI'></tbody>

                  <small id='UvZBI'></small><noframes id='UvZBI'>

                  本文介绍了使用 shift 修饰符从键码中获取键字符(值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我很幸运能找到 String.fromCharCode().它对我有很大帮助.但是,我注意到它没有考虑到 shift 修饰符.我知道 event.shiftKey 属性并使用它,但现在我需要获取考虑到 shift 键修饰符的键值(例如:A"或a").起初我使用 String.toLowerCase().. 但我忽略了数字键,举个例子:5"(不带移位)和%"(带移位).我需要在我的程序中区分这两者.获取键字符值的简单方法是什么?

                  I have been lucky to find String.fromCharCode(). It has helped me significantly. However, I noticed it doesn't take into account the shift modifier. I know the event.shiftKey property and use it, but right now I need to get the key value (eg: "A" or "a") which takes into account the shift key modifier. At first I used String.toLowerCase().. But I neglected to think of number keys, to give one example: "5" (without shift) and "%" (with shift). I need to differentiate between the two in my program. What's an easy way to get the key char value?

                  推荐答案

                  这种蛮力技术不是最漂亮的,但似乎很管用.我正在寻找相同的功能.

                  This brute force technique isn't the prettiest, but it seems to work. I'm in search of the same functionality.

                  function mapKeyPressToActualCharacter(isShiftKey, characterCode) {
                      if ( characterCode === 27 || characterCode === 8 || characterCode === 9 || characterCode === 20 || characterCode === 16 || characterCode === 17 || characterCode === 91 || characterCode === 13 || characterCode === 92 || characterCode === 18 ) {
                          return false;
                      }
                      if (typeof isShiftKey != "boolean" || typeof characterCode != "number") {
                          return false;
                      }
                      var characterMap = [];
                      characterMap[192] = "~";
                      characterMap[49] = "!";
                      characterMap[50] = "@";
                      characterMap[51] = "#";
                      characterMap[52] = "$";
                      characterMap[53] = "%";
                      characterMap[54] = "^";
                      characterMap[55] = "&";
                      characterMap[56] = "*";
                      characterMap[57] = "(";
                      characterMap[48] = ")";
                      characterMap[109] = "_";
                      characterMap[107] = "+";
                      characterMap[219] = "{";
                      characterMap[221] = "}";
                      characterMap[220] = "|";
                      characterMap[59] = ":";
                      characterMap[222] = """;
                      characterMap[188] = "<";
                      characterMap[190] = ">";
                      characterMap[191] = "?";
                      characterMap[32] = " ";
                      var character = "";
                      if (isShiftKey) {
                          if ( characterCode >= 65 && characterCode <= 90 ) {
                              character = String.fromCharCode(characterCode);
                          } else {
                              character = characterMap[characterCode];
                          }
                      } else {
                          if ( characterCode >= 65 && characterCode <= 90 ) {
                              character = String.fromCharCode(characterCode).toLowerCase();
                          } else {
                              character = String.fromCharCode(characterCode);
                          }
                      }
                      return character;
                  }
                  

                  这篇关于使用 shift 修饰符从键码中获取键字符(值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:检查字符串中的第一个字符 下一篇:React Native - 如何从 ScrollView 获取视图的 Y 偏移值

                  相关文章

                  最新文章

                  <legend id='Fphow'><style id='Fphow'><dir id='Fphow'><q id='Fphow'></q></dir></style></legend>

                      <bdo id='Fphow'></bdo><ul id='Fphow'></ul>
                  1. <tfoot id='Fphow'></tfoot>
                    1. <i id='Fphow'><tr id='Fphow'><dt id='Fphow'><q id='Fphow'><span id='Fphow'><b id='Fphow'><form id='Fphow'><ins id='Fphow'></ins><ul id='Fphow'></ul><sub id='Fphow'></sub></form><legend id='Fphow'></legend><bdo id='Fphow'><pre id='Fphow'><center id='Fphow'></center></pre></bdo></b><th id='Fphow'></th></span></q></dt></tr></i><div id='Fphow'><tfoot id='Fphow'></tfoot><dl id='Fphow'><fieldset id='Fphow'></fieldset></dl></div>

                      <small id='Fphow'></small><noframes id='Fphow'>