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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:45:00+00:00 2026-06-15T23:45:00+00:00

I know that you can listen to key press and down events with Dart

  • 0

I know that you can listen to key press and down events with Dart like:

var el = query('#el');
el.on.keyDown.add((e) {});

But the problem here is that it fires only once. I want repetition.

So, I tried keyPress instead, but it has a slight delay before the repetition. I am working on a game and I want it to fire instantly and repetitively.

  • 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-15T23:45:00+00:00Added an answer on June 15, 2026 at 11:45 pm

    First of all, don’t listen to keyPress events, because the “initial delay” depends on the operating system configuration! In fact, keyPress events may not even fire repetitively.

    What you need to do is to listen to keyDown and keyUp events. You can make a helper for this.

    class Keyboard {
      HashMap<int, int> _keys = new HashMap<int, int>();
    
      Keyboard() {
        window.onKeyDown.listen((KeyboardEvent e) {
          // If the key is not set yet, set it with a timestamp.
          if (!_keys.containsKey(e.keyCode))
            _keys[e.keyCode] = e.timeStamp;
        });
    
        window.onKeyUp.listen((KeyboardEvent e) {
          _keys.remove(e.keyCode);
        });
      }
    
      /**
       * Check if the given key code is pressed. You should use the [KeyCode] class.
       */
      isPressed(int keyCode) => _keys.containsKey(keyCode);
    }
    

    Then depending on what you do in your game, you probably have “a game loop” of some sort, in your update() method that gets called in every once in a while:

    class Game {
      Keyboard keyboard;
    
      Game() {
        keyboard = new Keyboard();
    
        window.requestAnimationFrame(update);
      }
    
      update(e) {
        if (keyboard.isPressed(KeyCode.A))
          print('A is pressed!');
    
        window.requestAnimationFrame(update);
      }
    }
    

    Now your game loop checks repetitively for A key pressing.

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

Sidebar

Related Questions

I know that can't use left join in indexed view. but I don't understand
I know that it's a subject that can raise a lot of debate, but
I know that I can track when the mouse is moved like this: $(body).mousemove(
I know that I can get the true bits with the simple loop, but
We know that we can launch an apk file, we can also listen the
I know that can co-exists with web form no problem as Hanselman mention here
I just want to know that can i make an application which have some
I want to know that can mouse click event detects colors or even strings.
I know that I can hijack a form by showing a login form in
I know that you can't repeat match groups in Lua. For example, if I

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.