#include <GLFW/glfw3.h>
// This function is called whenever a key is pressed or released
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (action == GLFW_PRESS)
{
// Print the key code when a key is pressed
printf("Key pressed: 0x%x\n", key);
}
}
int main()
{
// Initialize GLFW
if (!glfwInit())
{
return -1;
}
// Create a window
GLFWwindow* window = glfwCreateWindow(800, 600, "My OpenGL Window", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
// Make the window's context current
glfwMakeContextCurrent(window);
// Set the key callback function
glfwSetKeyCallback(window, key_callback);
// Main loop
while (!glfwWindowShouldClose(window))
{
// Render your scene here
// Swap the front and back buffers
glfwSwapBuffers(window);
// Poll for events
glfwPollEvents();
}
// Terminate GLFW
glfwTerminate();
return 0;
}
This code sets up a key