Thread: clearing the message queue or don't let messages get queued

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    clearing the message queue or don't let messages get queued

    In my program, this is what happens. It appears as if there are a ton of WM_KEYDOWN messages being racked up in the message queue, so when you finally let off the key, all the WM_KEYDOWN messages are being fired off, but you really want them to stop since you let off the key.

    I could see the problem being fixed by:

    a) clearing the message queue after dispatching each one

    b) using some sort of a timer to limit the amount of messages (???)

    c) somehow dont let the messages get stacked up in the queue, but have to wait until its empty.

    I'm new to windows programming, so don't really have an idea on how to do the above. Any help would be appreciated, thanks.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    I thought you were using GetASyncKeyState( ) and everything was working fine?
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    nah, it still did the problem i mentioned above. Did it work good for you?

    If it did, could you post the exe and main.cpp or whatever you changed?

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Okay, here you go!

    EDIT: I only changed your main.cpp , but I attached everything.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  5. #5
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    It doesn't work for me

    When I press the keys, the ship doesn't move for about 5 seconds and then it ZOOMS across off the screen.

  6. #6
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    One question though, in addition to a plea for help for my program:

    When one key is pressed, WM_KEYDOWN is sent. When another key at the same time is pressed, does it send a WM_KEYUP for the key you just had down?

    Let me explain why I ask:

    In my game, you hold down right, then up -- now they are both down. You let go of the up key and the ship stops moving. The only way my flag for moving right can be set to false is through WM_KEYUP. The ONLY way.


  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by Leeman_s
    One question though, in addition to a plea for help for my program:

    When one key is pressed, WM_KEYDOWN is sent. When another key at the same time is pressed, does it send a WM_KEYUP for the key you just had down?

    Let me explain why I ask:

    In my game, you hold down right, then up -- now they are both down. You let go of the up key and the ship stops moving. The only way my flag for moving right can be set to false is through WM_KEYUP. The ONLY way.

    It STILL doesn't work? I have no clue then! It works flawlessly for me. I should take a video with my digital camera just to show you

    There are a lot of issues with having a bunch of keys down at once. Sometimes it will overload the keyboard buffer and you will get "phantom" strikes. This will give the appearence of one key being pressed when it really isn't. The converse is true when you have a bunch down sometimes they won't be acknowledged at all.

    Let me look over your code again and see if I can see anything? Are you sure you ran the EXE I sent you??

    EDIT: I have no clue but you can try taking out the UpdateShip function and just putting the code inline in your main loop.

    Code:
      // Check for input
      if(GetAsyncKeyState(VK_LEFT))
        player.x -= player.dx;
    
      if(GetAsyncKeyState(VK_RIGHT))
        player.x += player.dx;
          
      if(GetAsyncKeyState(VK_UP))
        player.y -= player.dy;
    
      if(GetAsyncKeyState(VK_DOWN))
        player.y += player.dy;
    Last edited by MrWizard; 12-25-2002 at 07:02 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  2. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  3. help with queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-21-2002, 11:39 AM
  4. New Thread with same Message Queue?
    By genghis in forum Windows Programming
    Replies: 2
    Last Post: 01-31-2002, 06:17 PM
  5. queue help
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 10-29-2001, 09:38 AM