c++ - SDL Keypressing -


i trying make program able detect key-presses sdl.

my current code modified version of elses (trying work before making own version).

#include "sdl/sdl.h" #include <iostream> using namespace std;  int main(int argc, char* argv[]) {     //start sdl     if(0 != sdl_init(sdl_init_everything)) {             std::cout << "well i'm screwed\n";             return exit_failure;     }     sdl_surface* display;     display = sdl_setvideomode(640, 480, 32, sdl_hwsurface | sdl_doublebuf);     sdl_event event;     bool running = true;     std::cout << "cake"; //testing output (doesn't work)     while(running) {             std::cout << "pie"; //again, testing output , again doesn't work             if(sdl_pollevent(&event)) { //i have tried while statement                     switch(event.type) {                             case sdl_keydown:                                     std::cout << "down\n"; // have tried "<< std::endl" instead of "\n"                                     break;                             case sdl_keyup:                                     std::cout << "up\n";                                     break;                             case sdl_quit:                                     running = false;                                     break;                             default:                                     break;                     }             }     }     //quit sdl     sdl_quit();      return 0; } 

this code supposed detect key-down/up , output it, doesn't output anything.

my ultimate goal make detect konami code , something.

i update code above making identical 1 using (except added comments of people have suggested).

also if helps: g++ -o myprogram.exe mysource.cpp -lmingw32 -lsdlmain -lsdl command using compile. (if didn't figure out command, running windows (7).) no errors occur when compiling

i getting output whatsoever, leads me believe probs has nothing key-checking; there chance incorrect.

sdl needs window receive events.

uncomment sdl_setvideomode() call:

#include <sdl/sdl.h> #include <iostream> using namespace std;  int main( int argc, char* argv[] )  {     if( 0 != sdl_init(sdl_init_everything) )      {         std::cout << "well i'm screwed\n";         return exit_failure;     }      sdl_surface* display;     display = sdl_setvideomode(640, 480, 32, sdl_hwsurface | sdl_doublebuf);      sdl_event event;     bool running = true;     while(running)      {         if(sdl_pollevent(&event))          {             switch(event.type)              {             case sdl_keydown:                 std::cout << "down" << endl;                 break;             case sdl_keyup:                 std::cout << "up" << endl;                 break;             case sdl_quit:                 running = false;                 break;             default:                 break;             }         }     }      sdl_quit();     return 0; } 

Comments