<commit_before>#include "sys_local.h"
#include "ui_shared.h"

InputManager *Input = NULL;

const string keycodeNames[] = {
	"unknown",
	"a",
	"b",
	"c",
	"d",
	"e",
	"f",
	"g",
	"h",
	"i",
	"j",
	"k",
	"l",
	"m",
	"n",
	"o",
	"p",
	"q",
	"r",
	"s",
	"t",
	"u",
	"v",
	"w",
	"x",
	"y",
	"z",
	"1",
	"2",
	"3",
	"4",
	"5",
	"6",
	"7",
	"8",
	"9",
	"0",
	"enter",
	"esc",
	"backspace",
	"tab",
	"space",
	"-",
	"=",
	"[",
	"]",
	"\\",
	"\\",
	";",
	"'",
	"`",
	",",
	".",
	"/",
	"capslock",
	"f1",
	"f2",
	"f3",
	"f4",
	"f5",
	"f6",
	"f7",
	"f8",
	"f9",
	"f10",
	"f11",
	"f12",
	"printscreen",
	"scrolllock",
	"pause",
	"insert",
	"home",
	"pageup",
	"delete",
	"end",
	"pagedown",
	"right",
	"left",
	"down",
	"up",
#ifdef _WIN32
	"numlock",
#else
	"clear",
#endif
	"kp_divide",
	"kp_multiply",
	"kp_minus",
	"kp_plus",
	"kp_enter",
	"kp_1",
	"kp_2",
	"kp_3",
	"kp_4",
	"kp_5",
	"kp_6",
	"kp_7",
	"kp_8",
	"kp_9",
	"kp_period",
#ifdef _WIN32
	"contextual",
#else
	"compose",
#endif
	"power",
	// HACK
	"lctrl",
	"lshift",
	"lalt",
	"lgui",
	"rctrl",
	"rshift",
	"ralt",
	"rgui"
	// END HACK
};

void InitInput() {
	Input = new InputManager();
}

void DeleteInput() {
	delete Input;
}

void InputManager::SendKeyDownEvent(SDL_Keysym key, char* text) {
	SDL_Scancode k = key.scancode;
	auto it = find(thisFrameKeysDown.begin(), thisFrameKeysDown.end(), k);
	if(it != thisFrameKeysDown.end())
		return;
	thisFrameKeysDown.push_back(k);

	// TODO: keycatchers
	UI::KeyboardEvent(key, true, text);
}

void InputManager::SendKeyUpEvent(SDL_Keysym key, char* text) {
	SDL_Scancode k = key.scancode;
	auto it = find(thisFrameKeysDown.begin(), thisFrameKeysDown.end(), k);
	if(it == thisFrameKeysDown.end())
		return;
	thisFrameKeysDown.erase(it);

	// TODO: keycatchers
	UI::KeyboardEvent(key, false, text);
}

void InputManager::InputFrame() {
	SDL_PumpEvents();
	for(auto it = thisFrameKeysDown.begin(); it != thisFrameKeysDown.end(); ++it)
		ExecuteBind(binds[*it]);
}

void InputManager::BindCommand(const string& keycodeArg, string commandArg) {
	int i;
	for(i = 0; i < SDL_SCANCODE_F19; i++) {
		if(keycodeNames[i] == keycodeArg) // FIXME
			break;<commit_msg>Clear out previous input frame, so we don't clog up the system<commit_after>#include "sys_local.h"
#include "ui_shared.h"

InputManager *Input = NULL;

const string keycodeNames[] = {
	"unknown",
	"a",
	"b",
	"c",
	"d",
	"e",
	"f",
	"g",
	"h",
	"i",
	"j",
	"k",
	"l",
	"m",
	"n",
	"o",
	"p",
	"q",
	"r",
	"s",
	"t",
	"u",
	"v",
	"w",
	"x",
	"y",
	"z",
	"1",
	"2",
	"3",
	"4",
	"5",
	"6",
	"7",
	"8",
	"9",
	"0",
	"enter",
	"esc",
	"backspace",
	"tab",
	"space",
	"-",
	"=",
	"[",
	"]",
	"\\",
	"\\",
	";",
	"'",
	"`",
	",",
	".",
	"/",
	"capslock",
	"f1",
	"f2",
	"f3",
	"f4",
	"f5",
	"f6",
	"f7",
	"f8",
	"f9",
	"f10",
	"f11",
	"f12",
	"printscreen",
	"scrolllock",
	"pause",
	"insert",
	"home",
	"pageup",
	"delete",
	"end",
	"pagedown",
	"right",
	"left",
	"down",
	"up",
#ifdef _WIN32
	"numlock",
#else
	"clear",
#endif
	"kp_divide",
	"kp_multiply",
	"kp_minus",
	"kp_plus",
	"kp_enter",
	"kp_1",
	"kp_2",
	"kp_3",
	"kp_4",
	"kp_5",
	"kp_6",
	"kp_7",
	"kp_8",
	"kp_9",
	"kp_period",
#ifdef _WIN32
	"contextual",
#else
	"compose",
#endif
	"power",
	// HACK
	"lctrl",
	"lshift",
	"lalt",
	"lgui",
	"rctrl",
	"rshift",
	"ralt",
	"rgui"
	// END HACK
};

void InitInput() {
	Input = new InputManager();
}

void DeleteInput() {
	delete Input;
}

void InputManager::SendKeyDownEvent(SDL_Keysym key, char* text) {
	SDL_Scancode k = key.scancode;
	auto it = find(thisFrameKeysDown.begin(), thisFrameKeysDown.end(), k);
	if(it != thisFrameKeysDown.end())
		return;
	thisFrameKeysDown.push_back(k);

	// TODO: keycatchers
	UI::KeyboardEvent(key, true, text);
}

void InputManager::SendKeyUpEvent(SDL_Keysym key, char* text) {
	SDL_Scancode k = key.scancode;
	auto it = find(thisFrameKeysDown.begin(), thisFrameKeysDown.end(), k);
	if(it == thisFrameKeysDown.end())
		return;
	thisFrameKeysDown.erase(it);

	// TODO: keycatchers
	UI::KeyboardEvent(key, false, text);
}

void InputManager::InputFrame() {
	SDL_PumpEvents();
	for(auto it = thisFrameKeysDown.begin(); it != thisFrameKeysDown.end(); ++it)
		ExecuteBind(binds[*it]);
	thisFrameKeysDown.clear();
}

void InputManager::BindCommand(const string& keycodeArg, string commandArg) {
	int i;
	for(i = 0; i < SDL_SCANCODE_F19; i++) {
		if(keycodeNames[i] == keycodeArg) // FIXME
			break;
{'fraction_non_alphanumeric': 0.24105718842560947, 'fraction_numerical': 0.018683071314650263, 'mean_word_length': 4.122520420070011, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2703748', 'n_tokens_mistral': 2215, 'n_tokens_neox': 2141, 'n_words': 405}