Solved

keyboard buffering

Posted on 2002-05-08
3
334 Views
Last Modified: 2010-04-07
I'm currently working on a simple 2D game, and almost everything's complete expect for one disturbing problem. I decided to use keyboard for controlling the human ship:

case WM_KEYDOWN:
..if (!keyBlock)
....poManager->ReceiveKeyPress(wParam);
....keyBlock = true;
..return 0;

what the poManager does is to simply call another class' member function to do keyboard processing. (a set of switch-case statements that test which key has been pressed. -like UP, DOWN arrows, etc..)
A timer assigns the false value to keyBlock every 50ms.

The problem is when I'm controlling the ship, say I press the left arrow key, and hold it down. And then, just as every computer gamer does, I wish to go diagonally (left and up), and press the up arrow key. Unfortunately no. I keep going only left.

Is there any clean way to do this.
(I don't use directx, native win32 api)

0
Comment
Question by:kushcu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Expert Comment

by:Jan Louwerens
ID: 6999776
the 'keyblock' variable just specifies that a key was (and/or still is) pressed. Any other keypresses are lost or ignored.
Perhaps you should keep a list of boolean 'keyblock' variables, one for each key, and then test only the keyblock variable associated with that key in the WM_KEYDOWN message.
0
 
LVL 2

Accepted Solution

by:
kamarey earned 71 total points
ID: 7001552

class Someclass : public Baseclass
{
    // 128 - number of key;
    // 2 - two arrays, first column contain values
    // 'simple' keys, second column contain values
    // of extended keys(left, del, etc)
    BOOL key[128][2];
    DWORD nKeysPressed;

    Somwclass()
    {
        nKeysPressed = 0;
        FillMemory(key, 128 * 2 * sizeof(BOOL), 0);
    }
}

void Someclass::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
    if (!key[nChar][(nFlags & 256) == 256])
    {
        nKeysPressed++;

        key[nChar][(nFlags & 256) == 256] = TRUE;
    }

    Baseclass::OnKeyDown(nChar, nRepCnt, nFlags);
}

void Someclass::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
     if (nKeysPressed)
        nKeysPressed--;

    key[nChar][(nFlags & 256) == 256] = FALSE;
       
    Baseclass::OnKeyUp(nChar, nRepCnt, nFlags);
}

void Someclass::ShipMove()
{
    // Test left(VK_LEFT) extended(TRUE) key
    if (key[VK_LEFT][TRUE])
        dosometing;

    // Test key a(VK_A) not extended(FALSE)
    if (key[VK_A][FALSE])
        dosometing;

    etc
}
0
 

Author Comment

by:kushcu
ID: 7003488
I guess this stuff uses MFC, but anyway, the idea should solve the problem.
thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question