Need help turning this if sequence into a switch case

This is a discussion on Need help turning this if sequence into a switch case within the C++ Programming forums, part of the General Programming Boards category; How do you turn this.... Code: //macros to read the keyboard asynchronously #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    131

    Need help turning this if sequence into a switch case

    How do you turn this....
    Code:
    //macros to read the keyboard asynchronously
    #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
    #define KEY_UP(vk_code)((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
    
    	if (KEY_DOWN(VK_RIGHT))
    	{
    		right = right + 1;
    		left = left + 1;
    	}
    	if (KEY_DOWN(VK_LEFT))
    	{	
    		right = right -1;
    		left = left - 1;
    	}
    	if (KEY_DOWN(VK_UP))
    	{
    		top = top - 1;
    		bottom = bottom - 1;
    	}
    	if (KEY_DOWN(VK_DOWN))
    	{
    		bottom = bottom + 1;
    		top = top + 1;
    	}
    into a switch statment....

    This was my attempt at it but I could not figure out the whole call to KEY_DOWN aspect
    Code:
    	switch (KEY_DOWN())
    	{
    	case VK_RIGHT;
    		right = right + 1;
    		left = left + 1;
    		break;
    	case VK_LEFT;
    		right = right -1;
    		left = left - 1;
    		break;
    	case VK_UP;
    		top = top - 1;
    		bottom = bottom - 1;
    		break;
    	case VK_DOWN;
    		bottom = bottom + 1;
    		top = top + 1;
    		break;
    	default:
    		break;
    	}

  2. #2
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    this is just a wild guess, but have you tried finding out the return type of KEY_DOWN? in your if statements you have KEY_DOWN(VK_UP) and so on, they don't return those values do they?
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 02:01 AM
  3. Problems with switch()
    By duvernais28 in forum C Programming
    Replies: 13
    Last Post: 01-28-2005, 10:42 AM
  4. enumeration with switch case?
    By Shadow12345 in forum C++ Programming
    Replies: 17
    Last Post: 09-26-2002, 05:57 PM

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