Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

142
Visualizações
can i get the keycode value?

can i get the keycode value?, not the code.
i mean when you push "D" key on keyboard it will return 68, can it return "D" ? and i got nothing for shift key or tab key.
it is possible to do?

(function(){
let this_, keycode_;

$('textarea')
.on('keydown', function(e){
  this_ = e.target;
  keycode_  = e.keyCode || e.which;
})
.on('input', function(){
  $('#log').text( keycode_ ); 
})
.on('keyup', function(){

});

})();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!--
i want to get keycode_ value, not the code.
i mean when you push "D" key on keyboard it will return 68, can it return "D" ? and i got nothing for shift key or tab. 
can you solve this? 
-->
<textarea></textarea>

<div id="log"></div>

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Get the key property instead of the keyCode property from the event:

(function() {
  let this_, keycode_;

  $('textarea')
    .on('keydown', function(e) {
      this_ = e.target;
      keycode_ = e.keyCode == 9 ? 'Tab' : (e.shiftKey ? 'Shift' : (e.key || e.which));
      $(this).trigger('input');
    })
    .on('input', function() {
      $('#log').text(keycode_);
    })
    .on('keyup', function() {

    });

})();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!--
i want to get keycode_ value, not the code.
i mean when you push "D" key on keyboard it will return 68, can it return "D" ? and i got nothing for shift key or tab. 
can you solve this? 
-->
<textarea></textarea>

<div id="log"></div>


As an alternative, you can also use String.fromCharCode() to convert the key code to a character:

(function() {
  let this_, keycode_;

  $('textarea')
    .on('keydown', function(e) {
      this_ = e.target;
      keycode_ = String.fromCharCode(e.keyCode || e.which);
    })
    .on('input', function() {
      $('#log').text(keycode_);
    })
    .on('keyup', function() {

    });

})();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!--
i want to get keycode_ value, not the code.
i mean when you push "D" key on keyboard it will return 68, can it return "D" ? and i got nothing for shift key or tab. 
can you solve this? 
-->
<textarea></textarea>

<div id="log"></div>

about 4 years ago · Juan Pablo Isaza Relatório

0

so this is the final answer:

(function(){
let this_, keycode_;

$('#test_in')
.on('keydown', function(e){
  keycode_  = e.keyCode || e.which;
  if( keycode_ === 9 ){
    //tab key
    e.preventDefault(); // prevent input to losing focus, this will Cancel the default action
  }
  $('#log').text( e.key ); 
});

})();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!--
i want to get keycode_ value, not the code.
i mean when you push "D" key on keyboard it will return 68, can it return "D" ? and i got nothing for shift key or tab. 
can you solve this? 
-->
<textarea id="test_in"></textarea>

<div id="log"></div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda