mirror of
https://github.com/glfw/glfw.git
synced 2026-09-22 08:50:15 +00:00
Added a conservative set of key modifiers.
This commit is contained in:
+1
-1
@@ -74,7 +74,7 @@ static void cursor_position_callback(GLFWwindow* window, double x, double y)
|
||||
cursor_y = y;
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action)
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
{
|
||||
if (key == GLFW_KEY_SPACE && action == GLFW_PRESS)
|
||||
set_swap_interval(window, 1 - swap_interval);
|
||||
|
||||
+3
-9
@@ -39,18 +39,12 @@ static void usage(void)
|
||||
printf("Usage: clipboard [-h]\n");
|
||||
}
|
||||
|
||||
static GLboolean control_is_down(GLFWwindow* window)
|
||||
{
|
||||
return glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) ||
|
||||
glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL);
|
||||
}
|
||||
|
||||
static void error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action)
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
{
|
||||
if (action != GLFW_PRESS)
|
||||
return;
|
||||
@@ -62,7 +56,7 @@ static void key_callback(GLFWwindow* window, int key, int action)
|
||||
break;
|
||||
|
||||
case GLFW_KEY_V:
|
||||
if (control_is_down(window))
|
||||
if (mods == GLFW_MOD_CTRL)
|
||||
{
|
||||
const char* string;
|
||||
|
||||
@@ -75,7 +69,7 @@ static void key_callback(GLFWwindow* window, int key, int action)
|
||||
break;
|
||||
|
||||
case GLFW_KEY_C:
|
||||
if (control_is_down(window))
|
||||
if (mods == GLFW_MOD_CTRL)
|
||||
{
|
||||
const char* string = "Hello GLFW World!";
|
||||
glfwSetClipboardString(window, string);
|
||||
|
||||
+31
-8
@@ -36,6 +36,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
|
||||
// These must match the input mode defaults
|
||||
@@ -206,6 +207,22 @@ static const char* get_button_name(int button)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char* get_mods_name(int mods)
|
||||
{
|
||||
static char name[512];
|
||||
|
||||
name[0] = '\0';
|
||||
|
||||
if (mods & GLFW_MOD_SHIFT)
|
||||
strcat(name, " shift");
|
||||
if (mods & GLFW_MOD_CTRL)
|
||||
strcat(name, " control");
|
||||
if (mods & GLFW_MOD_ALT)
|
||||
strcat(name, " alt");
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
static const char* get_character_string(int character)
|
||||
{
|
||||
// This assumes UTF-8, which is stupid
|
||||
@@ -278,16 +295,19 @@ static void window_iconify_callback(GLFWwindow* window, int iconified)
|
||||
iconified ? "iconified" : "restored");
|
||||
}
|
||||
|
||||
static void mouse_button_callback(GLFWwindow* window, int button, int action)
|
||||
static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
|
||||
{
|
||||
const char* name = get_button_name(button);
|
||||
|
||||
printf("%08x at %0.3f: Mouse button %i", counter++, glfwGetTime(), button);
|
||||
|
||||
if (name)
|
||||
printf(" (%s) was %s\n", name, get_action_name(action));
|
||||
else
|
||||
printf(" was %s\n", get_action_name(action));
|
||||
printf(" (%s)", name);
|
||||
|
||||
if (mods)
|
||||
printf(" (with%s)", get_mods_name(mods));
|
||||
|
||||
printf(" was %s\n", get_action_name(action));
|
||||
}
|
||||
|
||||
static void cursor_position_callback(GLFWwindow* window, double x, double y)
|
||||
@@ -308,16 +328,19 @@ static void scroll_callback(GLFWwindow* window, double x, double y)
|
||||
printf("%08x at %0.3f: Scroll: %0.3f %0.3f\n", counter++, glfwGetTime(), x, y);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action)
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
{
|
||||
const char* name = get_key_name(key);
|
||||
|
||||
printf("%08x at %0.3f: Key 0x%04x", counter++, glfwGetTime(), key);
|
||||
|
||||
if (name)
|
||||
printf(" (%s) was %s\n", name, get_action_name(action));
|
||||
else
|
||||
printf(" was %s\n", get_action_name(action));
|
||||
printf(" (%s)", name);
|
||||
|
||||
if (mods)
|
||||
printf(" (with%s)", get_mods_name(mods));
|
||||
|
||||
printf(" was %s\n", get_action_name(action));
|
||||
|
||||
if (action != GLFW_PRESS)
|
||||
return;
|
||||
|
||||
+9
-9
@@ -48,17 +48,17 @@ static void window_size_callback(GLFWwindow* window, int width, int height)
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action)
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
{
|
||||
if (action != GLFW_PRESS)
|
||||
return;
|
||||
if (action != GLFW_PRESS)
|
||||
return;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case GLFW_KEY_SPACE:
|
||||
glfwSetTime(0.0);
|
||||
break;
|
||||
}
|
||||
switch (key)
|
||||
{
|
||||
case GLFW_KEY_SPACE:
|
||||
glfwSetTime(0.0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void usage(void)
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ static void error_callback(int error, const char* description)
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action)
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
{
|
||||
if (action != GLFW_PRESS)
|
||||
return;
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ static void error_callback(int error, const char* description)
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action)
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
{
|
||||
printf("%0.2f Key %s\n",
|
||||
glfwGetTime(),
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ static void window_size_callback(GLFWwindow* window, int width, int height)
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action)
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE)
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ static void cursor_position_callback(GLFWwindow* window, double x, double y)
|
||||
cursor_y = y;
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action)
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ static void window_close_callback(GLFWwindow* window)
|
||||
printf("Close callback triggered\n");
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action)
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
{
|
||||
if (action != GLFW_PRESS)
|
||||
return;
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ static void error_callback(int error, const char* description)
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action)
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
{
|
||||
if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE)
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ static void window_size_callback(GLFWwindow* window, int width, int height)
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int action)
|
||||
static void key_callback(GLFWwindow* window, int key, int action, int mods)
|
||||
{
|
||||
if (key == GLFW_KEY_SPACE && action == GLFW_PRESS)
|
||||
set_swap_interval(window, 1 - swap_interval);
|
||||
|
||||
Reference in New Issue
Block a user