I've frequented this site now for some time and have found its content to be very helpful, but I've come across a problem that I can't seem to find the answer to (I've Googled and searched this site, unsuccessfully). The problem is that I'm trying to implement a global keyboard input system in SDL/C++ and I'm having trouble with my basic IsKeyPress() method. I've been able to successfully make the InputHandler class into a Singleton, so I know that's not the problem; it seems that perhaps the way I'm trying to check for key input is flawed. Here is my method so far:
bool InputHandler::IsKeyPress(SDLKey key) {
if (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
if (event.key.keysym.sym == key) { // I am aware that this line doesn't work
return true; // however, this is the general method I'm
} // trying to implement.
}
}
Logger::Instance()->log(1, "Key Press Failure");
false;
}
You can see that I want to send in a key from wherever in the game and return true or false based on whether or not that key is currently down. Is this possible, given the method I'm trying to use? Or is there an easier way to handle input on a global scale?
I'm not a seasoned professional with SDL so I may have simply made a n00b mistake. Thanks for taking a look at my question and for any help you can provide.
Edit* I realize that the last line should read 'return false;'
That was merely a typo.

New Topic/Question
Reply




MultiQuote




|