text input

This commit is contained in:
John Alanbrook 2023-02-13 19:35:01 +00:00
parent fceb68a910
commit 93393be85b

View file

@ -115,11 +115,24 @@ void set_mouse_mode(int mousemode)
glfwSetInputMode(mainwin->window, GLFW_CURSOR, mousemode); glfwSetInputMode(mainwin->window, GLFW_CURSOR, mousemode);
} }
void char_cb(GLFWwindow *w, unsigned int codepoint)
{
for (int i = 0; i < arrlen(pawns); i++) {
if (!pawns[i] || script_eval_setup("input_text", pawns[i])) continue;
char out[2];
out[0] = (char)codepoint;
out[1] = 0;
duk_push_string(duk, out);
script_eval_exec(1);
}
}
void input_init() void input_init()
{ {
glfwSetCursorPosCallback(mainwin->window, cursor_pos_cb); glfwSetCursorPosCallback(mainwin->window, cursor_pos_cb);
glfwSetScrollCallback(mainwin->window, scroll_cb); glfwSetScrollCallback(mainwin->window, scroll_cb);
glfwSetMouseButtonCallback(mainwin->window, mb_cb); glfwSetMouseButtonCallback(mainwin->window, mb_cb);
glfwSetCharCallback(mainwin->window, char_cb);
} }
void call_input_signal(char *signal) { void call_input_signal(char *signal) {
@ -133,6 +146,7 @@ void call_input_signal(char *signal) {
} }
} }
const char *keyname_extd(int key, int scancode) { const char *keyname_extd(int key, int scancode) {
char keybuf[50]; char keybuf[50];
const char *kkey = NULL; const char *kkey = NULL;
@ -236,6 +250,10 @@ const char *keyname_extd(int key, int scancode) {
case GLFW_KEY_RIGHT_BRACKET: case GLFW_KEY_RIGHT_BRACKET:
kkey = "rbracket"; kkey = "rbracket";
break; break;
case GLFW_KEY_BACKSPACE:
kkey = "backspace";
break;
} }
if (kkey) return kkey; if (kkey) return kkey;