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 252055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:38:46+00:00 2026-05-11T21:38:46+00:00

N.B. Keep in mind the difference between key code and character code. For example,

  • 0

N.B. Keep in mind the difference between key code and character code. For example, the number 1 (one) and the character ! (bang) both have the same key code but different character codes. Likewise, the number 7 from the row of numbers and the number 7 from the numpad have different key codes but the same character codes.

I’m programming a music rhythm game in Adobe Flex and would like to bind keyboard keys. This isn’t a problem, but I certainly would have a problem, say, setting the default keys to A, S, D, and F and telling the user that this is the case.

If you take a look at the documentation for flash.ui.Keyboard, you’ll see that there are constants for keyboard keys to key codes. However, these are only available in Adobe AIR and not the browser. This makes sense since not all operating systems and keyboards are alike (or present!), so key codes can vary.

So, how can I assign default keys that have meaning instead of picking key codes and praying?

My only sane thought is to store the character codes for the key bindings and then provide an character code to String mapping so I can tell the user what to press. However, my gut tells me that this will break in subtle or not-so-subtle ways. Like CAPSLOCK.

Thanks.

Update: I am currently using radekg’s answer, but I still think that this will break easily. I would feel more comfortable with some persuasion that this is correct.

  • 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-11T21:38:46+00:00Added an answer on May 11, 2026 at 9:38 pm

    Radekg is mostly correct.

    Flash has a built in Class flash.ui.KeyLocation with four static properties: LEFT, RIGHT, NUM_PAD, STANDARD. This means that you can have a definitive idea which key has been pressed, even if the keyboard has been remapped. If you this in combination with String.fromCharCode, you should be able to solve this problem rather neatly.

    Your final code might look like:

    import flash.ui.KeyLocation;
    import flash.events.KeyboardEvent;
    
    function handleKeyboardEvent( event:KeyboardEvent )
    {
        // This will work for a majority of the keys.
        var key:String = String.fromCharCode( event.charCode ).toLowerCase();
    
        // Use strict comparison
        if( event.keyLocation !== KeyLocation.STANDARD )
        {
            // The key is a number, then it needs to be re-identified.
            if( event.keyLocation == KeyLocation.RIGHT  )    key = "r" + key;
            if( event.keyLocation == KeyLocation.LEFT   )      key = "l" + key;
            if( event.keyLocation == KeyLocation.NUM_PAD)   key = "n" + key;
        }
    
        switch( key )
        {
            case "r1":
                // Do something with the one which is not on the keypad.
                break;
            case "n.":
                // Do something with the number pad's period.
                break;
            case "n":
                // Do something with the letter N.
                break;
        }
    }
    

    I will admit, I am not certain what will happen with String.fromCharCode and control keys (F1, Alt, Ctrl, etc), but the KeyboardEvent does support event.shiftKey, event.ctrlKey, event.altKey

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Just tableData[row_index] = myData[row_index] May 11, 2026 at 11:42 pm
  • Editorial Team
    Editorial Team added an answer Have you debugged into some_func? Try to windbg that program.… May 11, 2026 at 11:42 pm
  • Editorial Team
    Editorial Team added an answer your approach is the fastest ... if you think it's… May 11, 2026 at 11:42 pm

Related Questions

We're in the process of replacing a legacy system. There is going to be
C++ is all about memory ownership - aka ownership semantics . It is the
I have a IBAction such as: - (IBAction)showPicker:(id)sender; How can I get the name
I'm looking for a data structure (or structures) that would allow me keep me

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.