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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:32:45+00:00 2026-06-16T17:32:45+00:00

I am making a simple game and I use the following code to detect

  • 0

I am making a simple game and I use the following code to detect cursor keys:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    if (Connection == null || Connection.IsOpen == false)
        return true;

    Thread.Sleep(SleepTime);

    switch (keyData)
    {
        case Keys.Up:
            GoForward();
            return true;

        case Keys.Right:
            GoRight();
            return true;

        case Keys.Left:
            GoLeft();
            return true;

        case Keys.Down:
            GoBackward();
            return true;

        case Keys.Space:
            Beep();
            return true;
    }

    return base.ProcessCmdKey(ref msg, keyData);
}

I also use this code to figure out if the user has released perviously presed key:

private void MainForm_KeyUp(object sender, KeyEventArgs e)
{
    StopRoomba();
}

I have 2 problems now: I want to add situation where user can press for example UP and RIGHT cursors simultaneously so the character goes up-right. How can I check for this condition in my code?

Also something strange happens (Or maybe its a default system). I can press 3 cursor keys at once or for example I hold UP key and then hold RIGHT key while still holding up and also holding DOWN while holding UP and RIGHT, my code reacts to all three codes. In the picture below you can see the red directions have been pressed and get detected by my code (red = pressed):

enter image description here

My second problem is that the MainForm_KeyUp sometimes does not detect key release and the character keeps going to the direction.

Any tips/helps will be appriciated

  • 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-16T17:32:47+00:00Added an answer on June 16, 2026 at 5:32 pm

    Keys is a flagged enumeration. Which means you can use bitwise comparisons to see if more than one key is pressed simultaneously.

    case Keys.Up & Keys.Right:
        ...
        break;
    

    You can also check for individual keys using checks like the following:

    if ((keyData & Keys.Up) == Keys.Up) 
        GoForward();
    if ((keyData & Keys.Right) == Keys.Right) 
        GoRight();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im making a simple rock paper scissors game and I need to use the
I'm making simple peer to peer game and I decided to use XML to
I am making a simple game project involving the use of Cocos2d. Now as
I'm making a simple game using the Windows Phone Silverlight and XNA Application type
I'm making a simple game in Javascript, in which when an object collides with
I am thinking of making a simple game engine for my course final year
I am also new to Java and Android Development, been making a simple game
I got a question about good practice. I'm making a simple game and, I'm
I am making simple grid like game ( grid is matrix 128x128) and matrix
I am making a simple multiplayer economic game in pygame. It consists of turns

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.