Original Post
how do i process up down left and right buttons in the console window using c++?
if(up key is press){move up // <-- dont worry about this part i know what to do here :P}Quote:
Original post by Gor435
close but no cigar im using windows btw
what if i wanna do somthing like this
*** Source Snippet Removed ***
any thoughts??
const int KEY_UP = 72;const int KEY_DOWN = 80;const int KEY_LEFT = 75;const int KEY_RIGHT = 77;const int KEY_EXTRA = 224;...input = getch();if (input == KEY_EXTRA){ input = getch(); if (input == KEY_UP) { // move up code }}#include <curses.h>initscr();loop int ch = getch(); if (ch == KEY_LEFT) // KEY_LEFT is defined by Curses. move_left();end loopendwin();Quote:
Original post by Gor435
how do i process up down left and right buttons in the console window using c++?
INPUT_RECORD inputBuffer[128];DWORD numberOfReadedRecords;if (!ReadConsoleInput(StdinHandle,inputBuffer,128,&numberOfReadedRecords) )fprintf(stderr,"ReadConsoleInput error: %d\n",GetLastError()); for (i = 0; i < cNumRead; i++) { switch(inputBuffer.EventType) { case KEY_EVENT: // keyboard input KeyEventProc(inputBuffer.Event.KeyEvent); break; case MOUSE_EVENT: // mouse input MouseEventProc(inputBuffer.Event.MouseEvent); break; case WINDOW_BUFFER_SIZE_EVENT: // scrn buf. resizing ResizeEventProc( inputBuffer.Event.WindowBufferSizeEvent); break; case FOCUS_EVENT: // disregard focus events case MENU_EVENT: // disregard menu events break; default: MyErrorExit("unknown event type"); break; } }DWORD temp;if (!GetNumberOfConsoleInputEvents(StdinHandle,&temp) )fprintf(stderr,"GetNumberOfConsoleInputEvents Error: %d\n",GetLastError());if (temp)// Waiting Inputs! do ReadConsoleInputelse// Idle StdinThis topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more