[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

keyboard buffering

Posted on 2002-05-08
3
Medium Priority
?
338 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 284 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

Independent Software Vendors: 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

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

650 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