Skip to content

Instantly share code, notes, and snippets.

Created October 5, 2016 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/fa27ad8ce5406445c3797544d6f1b7ce to your computer and use it in GitHub Desktop.
Save anonymous/fa27ad8ce5406445c3797544d6f1b7ce to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
#include <GLFW/glfw3.h>
// -----------------------------------------------------------------------------
// GLFW helpers
void glfw_key_callback(GLFWwindow *window, int key, int scan, int action, int mod);
static char keyMap[GLFW_KEY_LAST+1] = {0};
// -----------------------------------------------------------------------------
// main program
int main(void)
{
GLFWwindow *window;
glfwInit();
window = glfwCreateWindow(200, 200, "Keyboard Test", NULL, NULL);
glfwSetKeyCallback(window, glfw_key_callback);
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
if (keyMap[GLFW_KEY_UP])
printf("1\n");
else
printf("0\n");
usleep(16667); // ~60 fps
}
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
void glfw_key_callback(GLFWwindow *window, int key, int scan, int action, int mod)
{
if (action == GLFW_PRESS && key == GLFW_KEY_Q)
glfwSetWindowShouldClose(window, GL_TRUE);
if (action == GLFW_PRESS) {
printf("PRESS\n");
keyMap[key] = 1;
} else if (action == GLFW_RELEASE) {
printf("RELEASE\n");
keyMap[key] = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment