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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:29:06+00:00 2026-06-18T16:29:06+00:00

I am currently developing in XNA/C#. When the user presses a key ( Keys.Right

  • 0

I am currently developing in XNA/C#.
When the user presses a key (Keys.Right), I need to move an object.
I want this to happen

  1. when the user presses the key
  2. after 1 second while the user is holding the key and then every .25 seconds.

I already implemented the first one:

_kbOld = _kbNew;
_kbNew = _kb.GetState();
if(_kbNew.IsKeyDown(Keys.Right) &&
   _kbOld.IsKeyUp(Keys.Right))
{
    //Do something
}

How would I do the other actions?
I had the following ideas:

  • A Queue<KeyboardState>, keeping track of the last KeyboardStates

  • Saving the time the key was last pressed and when it was released (GameTime)

It should work like text input in Windows: When you hold a letter, it will repeat after a certain amount of time.

Which way should I use? Do you have other ideas?

Thanks in advance!

  • 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-18T16:29:08+00:00Added an answer on June 18, 2026 at 4:29 pm

    I would simply store the last push time, like you suggested:

    if (IsPressed())
    {
        // Key has just been pushed
        if (!WasPressed())
        {
            // Store the time
            pushTime = GetCurrentTime();
    
            // Execute the action once immediately
            // like a letter being printed when the button is pressed
            Action();
        }
    
        // Enough time has passed since the last push time
        if (HasPassedDelay())
        {
            Action();
        }   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently developing my first android application. I want the user of my application
Currently developing an application using the newest version of symfony, obtained through PEAR. This
Currently developing a PHP framework and have ran into my first problem. I need
I am currently developing an application and I need to be able when pressing
I am currently developing a C# .net xna game engine. I have been trying
Im currently developing a program that uses a scrollable/zoomable image as the main user
We're currently developing a game involving graphs (nodes connected by edges), and we want
I'm currently developing a 2D game with C#/XNA. The game's core feature are bullets
Im currently developing a system where the user will end up having large arrays(
I'm currently developing a project with XNA that is pulling information (ID, name, file

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.