ASCII control character html input text

前端 未结 5 1225
盖世英雄少女心
盖世英雄少女心 2021-02-08 10:00

I\'m trying to process input from a barcode scanner in a javascript browser app. The scanner output is a string of characters, which also contains at least one Group Separator c

5条回答
  •  孤独总比滥情好
    2021-02-08 10:43

    The input control ignores non printable characters like [GS]

    However, a barcode scanner usually emulates this character with CTRL+], which can be captured with the onkeydown event (key codes 17 and 221):

        var ctrlPressed = false;
        yourInput.addEventListener('onkeydown', function (event) {
           ctrlPressed = 17 === event.keyCode;
           if (221 === event.keyCode && ctrlPressed)
              // do what you want here (ie. modify the input value)
        });
    

    If this does not work you may want to check the codes first by logging them:

        yourInput.addEventListener('onkeydown', function (event) {
          console.log(event.keyCode)
        });
    

提交回复
热议问题