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

The Archive Base Latest Questions

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

On the window I bind two keydown events. The condition for triggering a callback

  • 0

On the window I bind two keydown events. The condition for triggering a callback function is a certain sequence:

Event #1: ["down", "right", "a"]
Event #2: ["down", "right", "down", "right", "a"]

How can I check if the user pressed the event 2 keys and then cancel the event 1?

Here is the code, focus on the red div and press the keys ▼ ► ▼ ► A, you will see the two events triggering. I need to know how can I check if a more precise one have been triggered…

To check if the sequence is right I compare the sequence with the end of the user input.

  • 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-16T17:17:27+00:00Added an answer on May 16, 2026 at 5:17 pm

    The more precise one, is the one with more keys. Alter your code so it only $(window).kb once, and to register a sequence, one calls another function that will fill an array structure similar to this:

    [
     {
        seq:["down", "right", "down", "right", "a"],
        callback: cb1
     },
     {
        seq:["down", "right", "a"],
        callback: cb2
     }
    ]
    

    the registration function will insert any new element in this array according to it’s seq.length, so this array will always be sorted more precise to less precise.

    Now your only $(window).kb, will each time loop this array looking for a match, once found, it will call the corresponding callback and stop iterating the array.

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

Sidebar

Related Questions

$(window).bind(beforeunload,function(){ return cant be seen in ff; }); The problem is that i can't
I am using this bit of code successfully: $(window).bind('resize',function() { window.location.href = window.location.href; });
If you are creating a WPF window or a WPF page, you can bind
Using AutoHotkey, How can I bind a hotkey to stretch/maximize/span a window across multiple
I'm using following code (purely for testing purposes): $(window).bind('unload', function() {alert('unload!')}); $(window).unload(function () {alert(".unload()")});
Is there any way to bind two windows from seprate processes together using Python/Pygame?
I'm using this $(window).bind('hashchange', gotohash); to add deep linking to my app. My problem
I have two modules like this (very very simplified): main.py: from window import *
I have a window that displays text. There are two parts to the text:
I have an ObservableCollection<Object> that contains two different types. I want to bind this

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.