# Poll a single input event at a time without a callback function?

**URL:** <https://discourse.glfw.org/t/poll-a-single-input-event-at-a-time-without-a-callback-function/74>\
**Category:** support\
**Created:** [June 24, 2014, 8:09pm UTC](https://discourse.glfw.org/t/poll-a-single-input-event-at-a-time-without-a-callback-function/74 "2014-06-24T20:09:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [June 24, 2014, 8:09pm UTC](https://discourse.glfw.org/t/poll-a-single-input-event-at-a-time-without-a-callback-function/74/1 "2014-06-24T20:09:15Z")

</div>

**[ltafoya](https://sourceforge.net/u/ltafoya/)** wrote on [Tuesday, June 24, 2014](https://sourceforge.net/p/glfw/discussion/247562/thread/d9fff8cd/#7624):

Hi. I would like to start by saying thank you for creating GLFW. I’m creating a 3D game engine and am having some difficulty trying to integrate your input handling into my component based design. I am using GLFW 3.0.4

In SFML (which was what I was using when I was learning how to do 2D games) I was able to process the input events one at a time from within my input system object like this

// check all the window’s events that were triggered since the last iteration of the loop  
sf::Event event;  
while(pWindow-\>pollEvent(event)) {  
// Handle event  
}

As far as I can tell with GLFW, I must register a callback function in order to process input events (or explicitly check the state of every key). However, my input system does not follow a singleton design pattern so giving it a static function to use as a callback would complicate my system more than I would like.

Is there a way to handle input in a way which is similar to the above SFML example? I would rather not include SFML in my project just for it’s input handling.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [June 24, 2014, 8:16pm UTC](https://discourse.glfw.org/t/poll-a-single-input-event-at-a-time-without-a-callback-function/74/2 "2014-06-24T20:16:46Z")

</div>

**[elmindreda](https://sourceforge.net/u/elmindreda/)** wrote on [Tuesday, June 24, 2014](https://sourceforge.net/p/glfw/discussion/247562/thread/d9fff8cd/#1162):

Use the window user pointer to find your input system object from the callbacks. [That’s what I do](https://github.com/elmindreda/Wendy/blob/master/src/Window.cpp#L470).

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [June 25, 2014, 2:18am UTC](https://discourse.glfw.org/t/poll-a-single-input-event-at-a-time-without-a-callback-function/74/3 "2014-06-25T02:18:58Z")

</div>

**[ltafoya](https://sourceforge.net/u/ltafoya/)** wrote on [Wednesday, June 25, 2014](https://sourceforge.net/p/glfw/discussion/247562/thread/d9fff8cd/#34eb):

Thank you for the fast response. I’ve been messing with it trying to get even a dummy static member function to work, but it crashes every time.

I have a  
static void KeyCallback(GLFWwindow \*window, int key, int scancode, int action, int mods);

KeyCallback is just a dummy function defined as  
void Input::KeyCallback(GLFWwindow \*window, int key, int scancode, int action, int mods) {}

I tried  
glfwSetKeyCallback(pWindow, KeyCallback);

But this function causes my program to crash. The compiler doesn’t give me any clues. When I comment out the glfwSetKeyCallback function, my program does not crash. I looked at your code and it looks like I’m using the same syntax as you.

Do you have any idea what could be going on?

EDIT: nevermind. I figured out what was wrong. I accidentally gave it a null pointer that I thought pointed to the GLFWwindow. My bad.

EDIT2: I now have glfwSetWindowUserPointer glfwGetWindowUserPointer working with static callback functions in my engine. Thank you for the advice and example.
