WM_KEYDOWM message

This is a discussion on WM_KEYDOWM message within the Windows Programming forums, part of the Platform Specific Boards category; I use the WM_KEYDOWN message(by checking wParam for a specific key of course) in my application to start an animation ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    27

    WM_KEYDOWM message

    I use the WM_KEYDOWN message(by checking wParam for a specific key of course) in my application to start an animation and use the WM_KEYUP message to tell when the key is released and stop the animation.

    But Windows have that autorepeat feature and when the key is preesed continuously many WM_KEYDOWN messages are received before an KEYUP message resulting my animation start again and again.

    How can I get rid of this?

    Thanks for help in advance!

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,549
    You can't. Check for the first message, set a flag, wait for keyup and reset the flag.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    27
    Thanks for reply. I came up to the following:
    Code:
    BOOL keys[256]; // Flags for all keys
    The keys array will be initialized to false.
    The WM_KEYUP handler:
    Code:
    case WM_KEYUP:
        keys[wParam] = FALSE;
        break;
    The WM_KEYDOWN handler:
    Code:
    case WM_KEYDOWN:
        if(keys[wParam] == FALSE)
        {
             keys[wParam] = TRUE;
             // The key is pressed for the first time
            /* ..... .... */
        }
        else
            // Key is already pressed pressed. Skip....
       
        break;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange string behavior
    By jcafaro10 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 07:38 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  3. Making a script language?
    By Blackroot in forum Game Programming
    Replies: 10
    Last Post: 02-16-2006, 01:22 AM
  4. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21