Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda