Thread: Win32 Api wParam key input problem

  1. #1
    Registered User
    Join Date
    Jul 2010

    Unhappy Win32 Api wParam key input problem

    So, I've been playing around with WinApi in C++. When i tried some key input i got a problem. I'm using WPARAM along with the WM_CHAR case. This is my input function:

    case WM_CHAR:
    //Later on
    void UpdateGameInput(WPARAM wParam)
    	if (wParam == VK_LEFT)
    		pPosition.x += -5;
    	else if (wParam == VK_UP)
    		pPosition.y += -5;
    	else if (wParam == VK_RIGHT)
    		pPosition.x += 5;
    	else if (wParam == VK_DOWN)
    		pPosition.y += 5;
    	else if (wParam == VK_ESCAPE)
    The VK_ESCAPE is working perfectly but the other ones doesn't seem to give any effect. pPosition is a point and is declared global in the beginning of the program:
    POINT pPosition;
    I'm using pPosition to draw a rectangle with my HDC and PAINTSTRUCT. The rectangle is showing itself, but it isn't moving the way i want it to:

    case WM_PAINT:
    hdc = BeginPaint(hwnd, &ps);
    			 pPosition.x - 10, pPosition.y - 10,
    			 pPosition.x + 10, pPosition.y + 10);
    		 EndPaint(hwnd, &ps);
    Please help me!

  2. #2
    train spotter
    Join Date
    Aug 2001
    near a computer
    Check the values in the POINT when you try to draw the rectangle.

    I can't see the POINTs initialisation nor any check to ensure it does not contain valid values (valuse that will not produce a negative coordinate or a point off the screen when drawing the rectangle).

    I also can't see the call that generates a WM_PAINT msg. It may not be invalidating the correct area.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    I'm not sure, but it would be better if u used WM_KEYDOWN instead WM_CHAR. I think WM_CHAR is called only by char input and limited others, like VK_ESCAPE
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with keyboard input
    By fighter92 in forum Game Programming
    Replies: 6
    Last Post: 03-20-2009, 09:41 AM
  2. Problem grabbing k/b input
    By falcon9 in forum C Programming
    Replies: 2
    Last Post: 10-28-2007, 11:47 AM
  3. Thread Synchronization :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-09-2002, 09:09 AM
  4. Win32 API Tutorials?
    By c++_n00b in forum C++ Programming
    Replies: 9
    Last Post: 05-09-2002, 03:51 PM
  5. Input Problem
    By Drew in forum C++ Programming
    Replies: 2
    Last Post: 10-19-2001, 07:19 AM