Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!