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

342
Views
¿Cómo usar JavaScript para presionar letras en el teclado?

Necesito obtener solo las letras presionadas en el teclado. He intentado usar:

 window.addEventListener("keydown", function(event) { letter = event.key; if(/[a-zA-Z]/.test(letter)) { console.log(letter); } });

Pero la consola muestra, por ejemplo, cuando se presionan "F12", "Shift", "CapsLock", "ArrowRight" y otras teclas que no son letras. ¿Cómo puedo resolver esto?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Utilice el evento onkeypress .

 function myKeyPress(e){ var keynum; if(window.event) { // IE keynum = e.keyCode; } else if(e.which){ // Netscape/Firefox/Opera keynum = e.which; } alert(String.fromCharCode(keynum)); }
 <input type="text" onkeypress="return myKeyPress(event)" />

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!