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

  • Home
  • SEARCH
  • 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 8903707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:56:13+00:00 2026-06-15T01:56:13+00:00

I have two event handlers, one for keydown and one for keyup. The keydown

  • 0

I have two event handlers, one for keydown and one for keyup. The keydown event handler triggers an alert message, but this prevents the keyup event from firing.

You can see a very simple example here: http://jsfiddle.net/boblauer/jaGwT/ When the keydown opens an alert, the keyup is not fired, but when an alert is not opened, the keyup is fired. Here’s the code from the jsfiddle:

var i = 0;
window.addEventListener('keydown', function(e) {
    if (i++ % 2) alert('down');
    console.log('down');
});

window.addEventListener('keyup', function(e) {
    alert('up');
    console.log('up');
});

I have a library that supports listening to multiple key combinations (such as ‘d + f’), so when a key is pressed, I need to add it to a list of keys that are currently pressed, and when a key is released, I need to remove it from said list. The problem I’m running to is, if I want an alert to show when d + f are pressed at the same time, my code to remove those keys from the ‘currently pressed’ list never fires, because my keyup handler is never called.

I can’t think of a good work around to this problem. Any ideas?

  • 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-15T01:56:14+00:00Added an answer on June 15, 2026 at 1:56 am

    The alert prevents the event from happening. What you could do instead is trigger this function manually, because it happens anyways.

    var keyupfunction = function(e){
        alert('up');
        console.log('up');
    }
    
    window.addEventListener('keyup', keyupfunction);
    
    window.addEventListener('keydown', function(e) {
        if (i++ % 2) alert('down');
        console.log('down');
        keyupfunction(e);
    });
    

    But really, you shouldn’t be using alerts. It prevents these events, but who knows what else it might break. Use something custom instead.

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

Sidebar

Related Questions

I have two event handlers wired up to a button click in a Windows
Suppose I have a event handler which makes two AJAX calls to the server:
What is the best way to share one function between two different event handlers?
I have two submit handlers, one validating a form and one submitting the form:
I have to event handlers attached to a form. The first one that fires
I have to event handlers attached to a form. The first one that fires
Say I have two click handlers which perform the same functionality : $('#div1').click(function(event) {
I have tracked two event values customReport1 and CustomReport 2 using GA event tracking
I have got two tables: Event +----------+---------+--------------+ | event_id | name | date |
I have two functions hooked on the submit event of a form. Each function

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.