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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:51:17+00:00 2026-06-08T15:51:17+00:00

We are creating a web user interface that looks like a desktop window. Now

  • 0

We are creating a web user interface that looks like a desktop window.
Now we need to handle the Alt key. When Alt key is pressed the focus goes to the upper menu.

In Javascript, how to get the event for Alt key when ONLY Alt key is pressed?

I need to ensure that no other key was pressed at the same time.

  • 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-06-08T15:51:21+00:00Added an answer on June 8, 2026 at 3:51 pm

    I don’t know if this is the most elegant solution, but it worked fine.

    $(function()
    {
        //Flag to check if another key was pressed with alt
        var vAnotherKeyWasPressed = false;
        //ALT keycode const
        var ALT_CODE = 18;
    
        //When some key is pressed
        $(window).keydown(function(event)
        {
            //Identifies the key
            var vKey = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
            //The last key pressed is alt or not? 
            vAnotherKeyWasPressed = vKey != ALT_CODE;
        });
    
        //When some key is left
        $(window).keyup(function(event)
        {
            //Identifies the key
            var vKey = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    
            //If the key left is ALT and no other key is pressed at the same time...
            if (!vAnotherKeyWasPressed && vKey == ALT_CODE)
            {
                //Focus the menu
                $('#myMenu').focus();
                //Stop the events for the key to avoid windows set the focus to the browser toolbar 
                return false;
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a web application that will have many users. Each user has
I am interested in creating a simple web application that will take in user
I have a web app I'm creating, where I need to allow the user
I'm trying to design an interface for a web-based application that allows the user
I'm creating a web page that user can send pm , receive it,add contact,response
I'm creating a web service with Rails 3.1 that requires authenticated user accounts for
I am creating a web form on asp.net that will allow the end user
I'm creating a web form that requires an user to upload a file in
I'm creating a web application with php and JavaScript that will get a user's
I'm creating a web application on Google AppEngine where I want the user to

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.