I am trying to make a simple text game, but I have come across an odd problem. I have a class set up to take inputs from the user's keyboard using SDL_KEYDOWN. When ever the function check_event() is called it runs a loop that polls keyboard input and returns a string for the button. The odd thing is that pressing down on the keys have no effect. The code stops for my while loop, but it seems like my function has no effect at all.
Here is my main code:
#include <iostream>
#include <fstream>
#include <SDL.h>
#include "SDL_ttf.h"
#include "input.h"
using namespace std;
Input input;
int main(int argc, char* argv[]) {
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) != 0) {
SDL_Log("Unable to initialize SDL: %s", SDL_GetError());
return 1;
}
cout << "Welcome to Hero V1.0!" << endl; //intro stuff
cout << "Written By: Jojo" << endl;
cout << endl;
cout << "1) New Game" << endl;
cout << "2) Continue Game" << endl;
while (true) {
string event = input.check_event();
if(event == "1"){
cout << "Test" << flush;
}
}
SDL_Quit();
return 0;
}
And here is my input class .cpp
#include <iostream>
#include <SDL.h>
#include "Input.h"
using namespace std;
string Input::check_event() {
while (SDL_PollEvent(&event)) {
if(event.type == SDL_KEYDOWN){
switch(event.key.keysym.sym){
case SDLK_1:
return "1";
}
}
}
return "null";
}
Any help is greatly appreciated