Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6867193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:16:44+00:00 2026-05-27T03:16:44+00:00

I am using the following event listener to capture keypresses: window.addEventListener(keydown, function(event) {} );

  • 0

I am using the following event listener to capture keypresses:

window.addEventListener("keydown", function(event) {} );

What is the easiest way to get a string which represents the key pressed, like the value of 33 would be “Pg Up”, 84 would be “F5”, 40 would be “Down Arrow” etc… Is there some useful javascript library for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:16:45+00:00Added an answer on May 27, 2026 at 3:16 am

    This website has a list. It seems it would be pretty easy to convert it to a set of constants or place it into an array.

    http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes

    Codes are for US keyboards. In fact, if you just steal their js…

     var keyPressed;
     if (charCode == 8) keyPressed = "backspace"; //  backspace
     if (charCode == 9) keyPressed = "tab"; //  tab
     if (charCode == 13) keyPressed = "enter"; //  enter
     if (charCode == 16) keyPressed = "shift"; //  shift
     if (charCode == 17) keyPressed = "ctrl"; //  ctrl
     if (charCode == 18) keyPressed = "alt"; //  alt
     if (charCode == 19) keyPressed = "pause/break"; //  pause/break
     if (charCode == 20) keyPressed = "caps lock"; //  caps lock
     if (charCode == 27) keyPressed = "escape"; //  escape
     if (charCode == 33) keyPressed = "page up"; // page up, to avoid displaying alternate character and confusing people
     if (charCode == 34) keyPressed = "page down"; // page down
     if (charCode == 35) keyPressed = "end"; // end
     if (charCode == 36) keyPressed = "home"; // home
     if (charCode == 37) keyPressed = "left arrow"; // left arrow
     if (charCode == 38) keyPressed = "up arrow"; // up arrow
     if (charCode == 39) keyPressed = "right arrow"; // right arrow
     if (charCode == 40) keyPressed = "down arrow"; // down arrow
     if (charCode == 45) keyPressed = "insert"; // insert
     if (charCode == 46) keyPressed = "delete"; // delete
     if (charCode == 91) keyPressed = "left window"; // left window
     if (charCode == 92) keyPressed = "right window"; // right window
     if (charCode == 93) keyPressed = "select key"; // select key
     if (charCode == 96) keyPressed = "numpad 0"; // numpad 0
     if (charCode == 97) keyPressed = "numpad 1"; // numpad 1
     if (charCode == 98) keyPressed = "numpad 2"; // numpad 2
     if (charCode == 99) keyPressed = "numpad 3"; // numpad 3
     if (charCode == 100) keyPressed = "numpad 4"; // numpad 4
     if (charCode == 101) keyPressed = "numpad 5"; // numpad 5
     if (charCode == 102) keyPressed = "numpad 6"; // numpad 6
     if (charCode == 103) keyPressed = "numpad 7"; // numpad 7
     if (charCode == 104) keyPressed = "numpad 8"; // numpad 8
     if (charCode == 105) keyPressed = "numpad 9"; // numpad 9
     if (charCode == 106) keyPressed = "multiply"; // multiply
     if (charCode == 107) keyPressed = "add"; // add
     if (charCode == 109) keyPressed = "subtract"; // subtract
     if (charCode == 110) keyPressed = "decimal point"; // decimal point
     if (charCode == 111) keyPressed = "divide"; // divide
     if (charCode == 112) keyPressed = "F1"; // F1
     if (charCode == 113) keyPressed = "F2"; // F2
     if (charCode == 114) keyPressed = "F3"; // F3
     if (charCode == 115) keyPressed = "F4"; // F4
     if (charCode == 116) keyPressed = "F5"; // F5
     if (charCode == 117) keyPressed = "F6"; // F6
     if (charCode == 118) keyPressed = "F7"; // F7
     if (charCode == 119) keyPressed = "F8"; // F8
     if (charCode == 120) keyPressed = "F9"; // F9
     if (charCode == 121) keyPressed = "F10"; // F10
     if (charCode == 122) keyPressed = "F11"; // F11
     if (charCode == 123) keyPressed = "F12"; // F12
     if (charCode == 144) keyPressed = "num lock"; // num lock
     if (charCode == 145) keyPressed = "scroll lock"; // scroll lock
     if (charCode == 186) keyPressed = ";"; // semi-colon
     if (charCode == 187) keyPressed = "="; // equal-sign
     if (charCode == 188) keyPressed = ","; // comma
     if (charCode == 189) keyPressed = "-"; // dash
     if (charCode == 190) keyPressed = "."; // period
     if (charCode == 191) keyPressed = "/"; // forward slash
     if (charCode == 192) keyPressed = "`"; // grave accent
     if (charCode == 219) keyPressed = "["; // open bracket
     if (charCode == 220) keyPressed = "\\"; // back slash
     if (charCode == 221) keyPressed = "]"; // close bracket
     if (charCode == 222) keyPressed = "'"; // single quote  var lblCharCode = getObject('spnCode');    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Extjs for my application. Which event/listener is fired when extjs completely
Setting onchange event for CheckBoxList using the following code doesn't work. chkListUserGroup.Attributes.Add(onchange, document.forms[0].isRecordModified.value='true';); How
I have the need of a click tab event. I am using the following
I am using following code in rowdatabound function. Protected Sub gvwMileStone_RowDataBound(ByVal sender As System.Object,
I have a custom event listener being added (fluently) to my configuration using: .ExposeConfiguration(c
I think this should be simple. Say I've got the following jQuery: $someForm.live('submit', function(event)
I am trying to get the GPS location of my G1 using the following
I am using following PHP code to connect to MS Access database: $odb_conn =
I am using following storedprocedure set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO Alter PROCEDURE
I'm using following peace of code to output an array: echo ======output without array_unique=====;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.