   SDL Events - Console App
  Just thought id take a quick break from my console text-based rpg, and do a little SDL. Im trying to make a console app where it draws something of a crosshair, and when you use the arrow keys it moves around. The problem is, my events arent being picked up, atleast I do not think so.#include <string>#include <iostream>#include "SDL.h"SDL_Event event;struct Coordinate {int x;int y;};void MoveLeft(Coordinate& c) {std::string output = "";if(c.x > 0){c.x -= 1;for(int i = 0; i < c.y; i++){output += "\n";}for(int i = 0; i < c.x; i++){output += " ";}output += "(+)";}std::cout << output;}void MoveRight(Coordinate& c){std::string output = "";if(c.x < 300){c.x += 1;for(int i = 0; i < c.y; i++){output += "\n";}for(int i = 0; i < c.x; i++){output += " ";}output += "(+)";}std::cout << output;}void MoveUp(Coordinate& c){std::string output = "";if(c.y > 0){c.y -= 1;for(int i = 0; i < c.y; i++){output += "\n";}for(int i = 0; i < c.x; i++){output += " ";}output += "(+)";}std::cout << output;}void MoveDown(Coordinate& c){std::string output = "";if(c.y < 300){c.y += 1;for(int i = 0; i < c.y; i++){output += "\n";}for(int i = 0; i < c.x; i++){output += " ";}output += "(+)";}std::cout << output;}int main(int argc, char* args[]) {if(SDL_Init(SDL_INIT_EVERYTHING) == -1)    {   return 1;    }std::cout << "(+)";bool quit = false;Coordinate c;c.x = 0;c.y = 0;while(!quit){// if an event is detectedif(SDL_PollEvent(&event)){std::cout << "rawr\n";// if a key was pressedif(event.type == SDL_KEYDOWN){switch(event.key.keysym.sym){case SDLK_UP:MoveUp(c);break;case SDLK_DOWN:MoveDown(c);break;case SDLK_LEFT:MoveLeft(c);break;case SDLK_RIGHT:MoveRight(c);break;}}}else if(event.type == SDL_QUIT)   {  //Quit the program  quit = true;   }}return 0;}I realize I need code in there to clear the screen during each movement, but for now the if statement thats directly in the while loop does not meet the condition. I used one of the lazy foo tutorials for the SDL code.   
  I guess you need to call SDL_SetVideoMode for events to work.if(SDL_Init(SDL_INIT_EVERYTHING) == -1){    return 1;}if (SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE) == -1){    return 1;};  Have you tried initializing the events on a separate thread?SDL_InitSubSystem(SDL_INIT_EVENTTHREAD);;  I think the messages processed by SDL only applies to the win32 window it creates ...If you're only concerned about the keyboard input, you can use GetKeyboardState function in <windows.h>.   ;  Possibly, but I have the project configured to be a console, as supposed to windows. Can always give the windows.h a shot   ;Quote:Original post by agm_ultimatexPossibly, but I have the project configured to be a console, as supposed to windows. Can always give the windows.h a shotThe functions in "windows.h" can be used from both. You can create gui objects or consoles from either console or windows projects. Don't think of that "windows.h" as meaning "windows_gui_stuff.h", more like "windows_operating_system.h".   ;  In that case I was referring to how I had the project settings configured for the SDL. The setup tutorial on lazy foo says to use the Windows under the susbsystem option in the linker settings of the project. I was using a console, so I switched it to console instead.   ;  Well I finished this small program. Im just wondering if clearing the screen can be done in a better way. I use system("cls"); for clearing the screen, but I was wondering if it was like the pause system function, where its better to go about other means of doing it. I did find some code on the web, but it only worked when moving the (+) left and right, not up and down.#include <string>#include <iostream>#include <windows.h>#include <stdio.h>#include <stdlib.h>// standard macro for reporting API Errors#define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \ on line %d\n", __FILE__, GetLastError(), api, __LINE__);}void ErrorExit(LPSTR);void KeyEventProc(KEY_EVENT_RECORD);void ResizeEventProc(WINDOW_BUFFER_SIZE_RECORD);struct Coordinate {int x;int y;};void cls(HANDLE hConsole){system("cls");/*COORD coordScreen = {0, 0}; // home the cursor hereBOOL bSuccess;DWORD cCharsWritten;CONSOLE_SCREEN_BUFFER_INFO csbi; // get the buffer infoDWORD dwConSize; // Number of characters in the buffer// get the number of character cells in the bufferbSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi);PERR(bSuccess, "GetConsoleScreenBufferInfo");dwConSize = csbi.dwSize.X * csbi.dwSize.Y;// fill screen with blanksbSuccess = FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize,coordScreen, &cCharsWritten);PERR(bSuccess, "FillConsoleOutputAttribute");// put the cursor at (0, 0)bSuccess = SetConsoleCursorPosition(hConsole, coordScreen);PERR(bSuccess, "SetConsoleCursorPosition")return;*/}void MoveLeft(Coordinate& c) {std::string output = "";if(c.x > 0){c.x -= 1;for(int i = 0; i < c.y; i++){output += "\n";}for(int i = 0; i < c.x; i++){output += " ";}output += "(+)";}std::cout << output;}void MoveRight(Coordinate& c){std::string output = "";if(c.x < 300){c.x += 1;for(int i = 0; i < c.y; i++){output += "\n";}for(int i = 0; i < c.x; i++){output += " ";}output += "(+)";}std::cout << output;}void MoveUp(Coordinate& c){std::string output = "";if(c.y > 0){c.y -= 1;for(int i = 0; i < c.y; i++){output += "\n";}for(int i = 0; i < c.x; i++){output += " ";}output += "(+)";}std::cout << output;}void MoveDown(Coordinate& c){std::string output = "";if(c.y < 300){c.y += 1;for(int i = 0; i < c.y; i++){output += "\n";}for(int i = 0; i < c.x; i++){output += " ";}output += "(+)";}std::cout << output;}int main(void) {HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);HANDLE hStdin;DWORD cNumRead, fdwMode, fdwSaveOldMode, i;INPUT_RECORD irInBuf[128];int counter = 0;// Get the standard input handlehStdin = GetStdHandle(STD_INPUT_HANDLE);if(hStdin == INVALID_HANDLE_VALUE){ErrorExit(TEXT("GetStdHandle"));}// save the current input mode, to be restored on exitif(!GetConsoleMode(hStdin, &fdwSaveOldMode)){ErrorExit(TEXT("GetConsoleMode"));}// enable the window and mouse input eventsfdwMode = ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT;if(!SetConsoleMode(hStdin, fdwMode)){ErrorExit(TEXT("SetConsoleMode"));}std::cout << "(+)";bool quit = false;Coordinate c;c.x = 0;c.y = 0;while(!quit){// if an event is detectedif(!ReadConsoleInput(hStdin,// input buffer handleirInBuf,// buffer to read into128,// size of read buffer&cNumRead)) // number of records to read{ErrorExit(TEXT("ReadConsoleInput"));}// dispatch events to appropriate handlerfor(i = 0; i < cNumRead; i++){switch(irInBuf.EventType){case KEY_EVENT:if(irInBuf.Event.KeyEvent.wVirtualKeyCode == VK_LEFT){cls(hConsole);MoveLeft(c);}else if(irInBuf.Event.KeyEvent.wVirtualKeyCode == VK_RIGHT){cls(hConsole);MoveRight(c);}else if(irInBuf.Event.KeyEvent.wVirtualKeyCode == VK_UP){cls(hConsole);MoveUp(c);}else if(irInBuf.Event.KeyEvent.wVirtualKeyCode == VK_DOWN){cls(hConsole);MoveDown(c);}break;}}}return 0;}void ErrorExit(LPSTR lpszMessage){fprintf(stderr, "%s\n", lpszMessage);//ExitProcess(0);}void KeyEventProc(KEY_EVENT_RECORD ker){    printf("Key event: ");    if(ker.bKeyDown){}}void ResizeEventProc(WINDOW_BUFFER_SIZE_RECORD wbsr){    printf("Resize event\n");};  In Windows you can use WriteConsoleOutput() or WriteConsoleOutputCharacter() to clear the screen. You could also try a curses library like pdcurses which sounds like would contain the functionality you seem to be trying to create.   