Thread: FAQ: Directional Keys - Useing in Console

  1. #31
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    Testing PHP...
    PHP Code:
    int main()
    {
    cout << "Hello World!";
    return 
    0;

    what does signature stand for?

  2. #32
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    YEY!! PHP!!.. But the code colours are kinda anti-C++, maybe we should ask an admin to change them...
    what does signature stand for?

  3. #33
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by BMJ

    end_game = end_game--; //Game_Over is reduced by 1
    Change this!!

    end_game--;
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  4. #34
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    thnx bmj, i been under alot of stress maybe thats why it was so hard.

  5. #35
    Yes. I agree with sangdrax. you need to change the way you increment and decrement. i gor teally woird things coming out of my early progs when i would use x = x++. Use x++ by itself, or x += 1. (except with your variables in there.)
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  6. #36
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    yea i have been scince i posted that code i went back and changed it, thnx for pointing it out anyway tho.

  7. #37
    Registered User
    Join Date
    Oct 2002
    Posts
    32
    The virtual key codes are found in winuser.h (which including windows.h will include)

    Here are a couple of macros you can use to check the state of a key.

    KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
    KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

    Using this method relieves the problem of having to get key input from the standard input.

    Check out the win32 console API for more neat ideas.

    If for whatever reason they VK codes don't seem to be defined here you go:
    Code:
    #define VK_LBUTTON		0x01 // Left mouse button  
    #define VK_RBUTTON		0x02 // Right mouse button  
    #define VK_CANCEL		0x03 // Control-break processing  
    #define VK_MBUTTON		0x04 // Middle mouse button (three-button mouse)  
    
    #define VK_BACK			0x08 // backspace key  
    #define VK_TAB			0x09 // tab key  
    
    #define VK_CLEAR		0x0C // clear key  
    #define VK_RETURN		0x0D // enter key  
    
    #define VK_SHIFT		0x10 // shift key  
    #define VK_CONTROL		0x11 // ctrl key  
    #define VK_MENU			0x12 // alt key  
    #define VK_PAUSE		0x13 // pause key  
    #define VK_CAPITAL		0x14 // caps lock key  
    
    #define VK_ESCAPE		0x1B // esc key  
    #define VK_SPACE		0x20 // spacebar  
    #define VK_PRIOR		0x21 // page up key  
    #define VK_NEXT			0x22 // page down key  
    #define VK_END			0x23 // end key  
    #define VK_HOME			0x24 // home key  
    #define VK_LEFT			0x25 // left arrow key  
    #define VK_UP			0x26 // up arrow key  
    #define VK_RIGHT		0x27 // right arrow key  
    #define VK_DOWN			0x28 // down arrow key  
    #define VK_SELECT		0x29 // select key  
    #define VK_EXECUTE		0x2B // execute key  
    #define VK_SNAPSHOT		0x2C // print screen key  
    #define VK_INSERT		0x2D // ins key  
    #define VK_DELETE		0x2E // del key  
    #define VK_HELP			0x2F // help key  
    #define VK_0			0x30 // 0 key  
    #define VK_1			0x31 // 1 key  
    #define VK_2			0x32 // 2 key  
    #define VK_3			0x33 // 3 key  
    #define VK_4			0x34 // 4 key  
    #define VK_5			0x35 // 5 key  
    #define VK_6			0x36 // 6 key  
    #define VK_7			0x37 // 7 key  
    #define VK_8			0x38 // 8 key  
    #define VK_9			0x39 // 9 key  
    
    #define VK_A			0x41 // a key  
    #define VK_B			0x42 // b key  
    #define VK_C			0x43 // c key  
    #define VK_D			0x44 // d key  
    #define VK_E			0x45 // e key  
    #define VK_F			0x46 // f key  
    #define VK_G			0x47 // g key  
    #define VK_H			0x48 // h key  
    #define VK_I			0x49 // i key  
    #define VK_J			0x4A // j key  
    #define VK_K			0x4B // k key  
    #define VK_L			0x4C // l key  
    #define VK_M			0x4D // m key  
    #define VK_N			0x4E // n key  
    #define VK_O			0x4F // o key  
    #define VK_P			0x50 // p key  
    #define VK_Q			0x51 // q key  
    #define VK_R			0x52 // r key  
    #define VK_S			0x53 // s key  
    #define VK_T			0x54 // t key  
    #define VK_U			0x55 // u key  
    #define VK_V			0x56 // v key  
    #define VK_W			0x57 // w key  
    #define VK_X			0x58 // x key  
    #define VK_Y			0x59 // y key  
    #define VK_Z			0x5A // z key  
    #define VK_LWIN			0x5B // Left Windows key (Microsoft Natural Keyboard)  
    #define VK_RWIN			0x5C // Right Windows key (Microsoft Natural Keyboard)  
    #define VK_APPS			0x5D // Applications key (Microsoft Natural Keyboard)  
    
    #define VK_NUMPAD0		0x60 // Numeric keypad 0 key  
    #define VK_NUMPAD1		0x61 // Numeric keypad 1 key  
    #define VK_NUMPAD2		0x62 // Numeric keypad 2 key  
    #define VK_NUMPAD3		0x63 // Numeric keypad 3 key  
    #define VK_NUMPAD4		0x64 // Numeric keypad 4 key  
    #define VK_NUMPAD5		0x65 // Numeric keypad 5 key  
    #define VK_NUMPAD6		0x66 // Numeric keypad 6 key  
    #define VK_NUMPAD7		0x67 // Numeric keypad 7 key  
    #define VK_NUMPAD8		0x68 // Numeric keypad 8 key  
    #define VK_NUMPAD9		0x69 // Numeric keypad 9 key  
    #define VK_MULTIPLY		0x6A // Multiply key  
    #define VK_ADD			0x6B // Add key  
    #define VK_SEPARATOR	0x6C // Separator key  
    #define VK_SUBTRACT		0x6D // Subtract key  
    #define VK_DECIMAL		0x6E // Decimal key  
    #define VK_DIVIDE		0x6F // Divide key  
    #define VK_F1			0x70 // f1 key  
    #define VK_F2			0x71 // f2 key  
    #define VK_F3			0x72 // f3 key  
    #define VK_F4			0x73 // f4 key  
    #define VK_F5			0x74 // f5 key  
    #define VK_F6			0x75 // f6 key  
    #define VK_F7			0x76 // f7 key  
    #define VK_F8			0x77 // f8 key  
    #define VK_F9			0x78 // f9 key  
    #define VK_F10			0x79 // f10 key  
    #define VK_F11			0x7A // f11 key  
    #define VK_F12			0x7B // f12 key  
    #define VK_F13			0x7C // f13 key  
    #define VK_F14			0x7D // f14 key  
    #define VK_F15			0x7E // f15 key  
    #define VK_F16			0x7F // f16 key  
    #define VK_F17			0x80H // f17 key  
    #define VK_F18			0x81H // f18 key  
    #define VK_F19			0x82H // f19 key  
    #define VK_F20			0x83H // f20 key  
    #define VK_F21			0x84H // f21 key  
    #define VK_F22			0x85H // f22 key  
    #define VK_F23			0x86H // f23 key  
    #define VK_F24			0x87H // f24 key  
    
    #define VK_NUMLOCK		0x90 // num lock key  
    #define VK_SCROLL		0x91 // scroll lock key  
    
    #define VK_ATTN			0xF6 // Attn key 
    #define VK_CRSEL		0xF7 // CrSel key 
    #define VK_EXSEL		0xF8 // ExSel key 
    #define VK_EREOF		0xF9 // Erase EOF key 
    #define VK_PLAY			0xFA // Play key 
    #define VK_ZOOM			0xFB // Zoom key 
    #define VK_NONAME		0xFC // Reserved for future use.  
    #define VK_PA1			0xFD // PA1 key 
    #define VK_OEM_CLEAR	0xFE // Clear key
    Last edited by Divx; 10-06-2002 at 01:50 PM.

  8. #38
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    wow divx u just totally lost me. My problem isn't really getting it to recognize keys being hit, that it does. After i hit up 14 billion times to get the prog going, which interns ventures me north then ouputs half of what it should then does it again. It should come up, tell me to pick a direction, then i hit say up and it goes once. It has to be something with my loop, heres the crazy ass output:

    NOTE: i didn't cut off, this is right outta the console.

    Code:
                           ***************************
                           ****     Caverns        ***
                           ****  Steven Billington ***
                           ***************************
    
    North = Up Arrow
    South = Down Arrow
    West = Left Arrow
    East = Right Arrow
    
    Home = Information
    
    Insert = Health
    P = Points
    
    End = Exit
    
    Select Action: You venture north.
    
    Select Action: You venture north.
    
    Select Action: You venture north.
    
    Select Action: You venture north.
    
    Select Action: You venture north.
    
    Select Action: You venture north.
    
    You can not continue in this direction.
    Select Action: You venture north.
    
    You can not continue in this direction.
    Select Action: You venture north.
    
    You can not continue in this direction.
    Select Action: You venture north.
    
    You can not continue in this direction.
    Select Action: You venture north.
    
    You can not continue in this direction.
    Select Action: You venture east.
    
    Select Action: You venture east.
    
    Select Action: You venture east.
    
    Select Action: You venture east.
    
    Select Action: You venture west.
    
    Select Action: You venture west.
    
    Select Action: You venture west.
    
    Select Action: You venture west.
    
    Select Action: You venture west.
    
    Select Action: Not an option!
    
    Select Action: Not an option!
    
    Select Action: You venture west.
    
    Select Action: You venture west.
    
    Select Action: You venture west.
    
    Select Action: You venture west.
    
    Select Action: You venture west.
    
    You can not continue in this direction.
    Select Action: Not an option!
    
    Select Action: You venture west.
    
    You


    Now this would normally be right if it didn't take 40 thousand key hits to react, and didn't cut off text...

  9. #39
    Registered User
    Join Date
    Oct 2002
    Posts
    32
    Code:
    if (KEY_DOWN(vk_code))
    {
    	while (!KEY_UP(vk_code))
    	{
    		// do action while key is down and not up
    	}
    	// do whatever when key is let go
    
    	// Suggest doing this to flush the standard input stream buffer
    	FlushConsoleInputBuffer (GetStdHandle(STD_INPUT_HANDLE));
    }
    Use that, hit it once and it'll execute once and won't continue executing (unless you want it to).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wiki FAQ
    By dwks in forum A Brief History of Cprogramming.com
    Replies: 192
    Last Post: 04-29-2008, 01:17 PM
  2. directional keys @ console
    By ipe in forum C Programming
    Replies: 1
    Last Post: 03-13-2003, 06:25 AM
  3. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM
  4. Arrow keys in console?
    By SyntaxBubble in forum C++ Programming
    Replies: 3
    Last Post: 02-02-2002, 06:12 PM