Created
October 5, 2016 18:31
-
-
Save anonymous/fa27ad8ce5406445c3797544d6f1b7ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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