Keyboard via the game's physical-keyboard input, window-sized surface with live resize, fullscreen shortcuts

This commit is contained in:
CRTkafa 2026-10-16 00:16:38 +08:00
parent dc575f7e5f
commit 70c01e38e4
3 changed files with 170 additions and 11 deletions

View file

@ -27,10 +27,20 @@ tools/make_app.sh
open "dist/Spy Mouse.app" open "dist/Spy Mouse.app"
``` ```
## Controls
- Mouse: tap, drag and draw paths (the game's touch input)
- Esc: Android Back (pause in a level, back in menus); other keys go to the game's physical-keyboard input
- Cmd+F, F11 or Alt+Enter: fullscreen; Cmd+W or Cmd+Q: quit (the game saves first)
- Any window size or aspect ratio: the game gets a surface of the window's pixel size and lays itself out for it,
like an Android device with that screen; resizing sends a surface change
Saves and the log go to `~/Library/Application Support/SpyMouse/`. Saves and the log go to `~/Library/Application Support/SpyMouse/`.
## Testing ## Testing
`--headless` runs without showing a window. `--control DIR` accepts commands written to `DIR/cmd` `--headless` runs without showing a window. `--control DIR` accepts commands written to `DIR/cmd`
(`tap X Y`, `drag X1 Y1 X2 Y2 [frames]`, `wait N`, `shot NAME`, `pause`, `resume`, `quit`), see `tools/ctl.sh`. (`tap X Y`, `drag X1 Y1 X2 Y2 [frames]`, `wait N`, `shot NAME`, `pause`, `resume`, `quit`), see `tools/ctl.sh`.
Other flags: `--skip-video`, `--frames N`, `--shot F1,F2`, `--gl-trace`, `--check-present`, `--verbose`. Input that goes through the real SDL event path: `click X Y`, `mdrag X1 Y1 X2 Y2 [frames]`, `press SDLKEY` (window points);
`resize W H`, `key ANDROIDKEY`.
Other flags: `--size WxH`, `--surface-scale S`, `--skip-video`, `--frames N`, `--shot F1,F2`, `--gl-trace`, `--check-present`, `--verbose`.

View file

@ -494,7 +494,9 @@ static void register_java() {
java_impl(cl, "<init>", [](JCall&) { return JVal{}; }); java_impl(cl, "<init>", [](JCall&) { return JVal{}; });
} }
java_impl("com/ea/blast/PowerManagerAndroid", "ApplyKeepAwake", [](JCall&) { return JVal{}; }); java_impl("com/ea/blast/PowerManagerAndroid", "ApplyKeepAwake", [](JCall&) { return JVal{}; });
java_impl("com/ea/blast/PhysicalKeyboardAndroidDelegate", "IsPhysicalKeyboardVisible", [](JCall&) { return JVal::I(0); }); // a Mac always has a hardware keyboard (Configuration.hardKeyboardHidden == NO)
java_impl("com/ea/blast/PhysicalKeyboardAndroidDelegate", "IsPhysicalKeyboardVisible", [](JCall&) { return JVal::I(1); });
java_impl("com/ea/blast/PhysicalKeyboardAndroidDelegate", "IsNavigationVisible", [](JCall&) { return JVal::I(1); });
for (const char* m : {"SetEnabled", "OnLifeCycleFocusGained", "OnLifeCycleFocusLost", "OnLifeCyclePause", "OnLifeCycleResume"}) { for (const char* m : {"SetEnabled", "OnLifeCycleFocusGained", "OnLifeCycleFocusLost", "OnLifeCyclePause", "OnLifeCycleResume"}) {
java_impl("com/ea/blast/DeviceOrientationHandlerAndroidDelegate", m, [](JCall&) { return JVal{}; }); java_impl("com/ea/blast/DeviceOrientationHandlerAndroidDelegate", m, [](JCall&) { return JVal{}; });
java_impl("com/ea/blast/AccelerometerAndroidDelegate", m, [](JCall&) { return JVal{}; }); java_impl("com/ea/blast/AccelerometerAndroidDelegate", m, [](JCall&) { return JVal{}; });

View file

@ -47,6 +47,8 @@ struct Options {
std::string control_dir; std::string control_dir;
bool check_present = false; bool check_present = false;
int max_seconds = 600; int max_seconds = 600;
int win_w = 960, win_h = 640; // initial window size in points
float surface_scale = 0; // surface pixels per window point (0 = auto)
}; };
static uint32_t native(const char* name) { static uint32_t native(const char* name) {
@ -63,6 +65,32 @@ static uint32_t call_native(const char* name, std::vector<uint32_t> args) {
static std::string pending_shot; static std::string pending_shot;
// SDL key -> Android KeyEvent keycode. Esc is Android's Back key.
static int android_keycode(SDL_Keycode k) {
if (k >= SDLK_A && k <= SDLK_Z) return 29 + (int)(k - SDLK_A);
if (k >= SDLK_0 && k <= SDLK_9) return 7 + (int)(k - SDLK_0);
switch (k) {
case SDLK_ESCAPE: return 4; // KEYCODE_BACK
case SDLK_BACKSPACE: return 67; // KEYCODE_DEL
case SDLK_RETURN: case SDLK_KP_ENTER: return 66;
case SDLK_SPACE: return 62;
case SDLK_TAB: return 61;
case SDLK_UP: return 19;
case SDLK_DOWN: return 20;
case SDLK_LEFT: return 21;
case SDLK_RIGHT: return 22;
case SDLK_MENU: return 82;
case SDLK_COMMA: return 55;
case SDLK_PERIOD: return 56;
case SDLK_MINUS: return 69;
case SDLK_EQUALS: return 70;
case SDLK_SLASH: return 76;
case SDLK_SEMICOLON: return 74;
case SDLK_APOSTROPHE: return 75;
default: return 0;
}
}
// Android runs activity callbacks and touch input on the UI thread and rendering on the GL thread. // Android runs activity callbacks and touch input on the UI thread and rendering on the GL thread.
// The engine relies on that split (e.g. NativeOnPause waits for the render thread), so we keep it. // The engine relies on that split (e.g. NativeOnPause waits for the render thread), so we keep it.
struct UiThread { struct UiThread {
@ -162,6 +190,8 @@ int main(int argc, char** argv) {
else if (a == "--control") opt.control_dir = next(); else if (a == "--control") opt.control_dir = next();
else if (a == "--check-present") opt.check_present = true; else if (a == "--check-present") opt.check_present = true;
else if (a == "--max-seconds") opt.max_seconds = atoi(next().c_str()); else if (a == "--max-seconds") opt.max_seconds = atoi(next().c_str());
else if (a == "--size") sscanf(next().c_str(), "%dx%d", &opt.win_w, &opt.win_h);
else if (a == "--surface-scale") opt.surface_scale = atof(next().c_str());
else if (a == "--gl-trace") gl_set_trace(true); else if (a == "--gl-trace") gl_set_trace(true);
} }
// Locate the game data: --game, next to the app bundle, or next to the executable. // Locate the game data: --game, next to the app bundle, or next to the executable.
@ -209,12 +239,14 @@ int main(int argc, char** argv) {
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
const int W = 960, H = 640; // The game renders into an offscreen surface sized from the window (like an Android device of that
// resolution); it is resized whenever the window changes, as Android does on configuration changes.
int W = 960, H = 640;
SDL_WindowFlags wf = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY; SDL_WindowFlags wf = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY;
if (opt.headless) wf |= SDL_WINDOW_HIDDEN; if (opt.headless) wf |= SDL_WINDOW_HIDDEN;
SDL_Window* win = SDL_CreateWindow("Spy Mouse", W, H, wf); SDL_Window* win = SDL_CreateWindow("Spy Mouse", opt.win_w, opt.win_h, wf);
if (!win) { logf("SDL_CreateWindow: %s", SDL_GetError()); return 1; } if (!win) { logf("SDL_CreateWindow: %s", SDL_GetError()); return 1; }
SDL_SetWindowAspectRatio(win, 1.5f, 1.5f); SDL_SetWindowMinimumSize(win, 480, 320);
SDL_GLContext gl = SDL_GL_CreateContext(win); SDL_GLContext gl = SDL_GL_CreateContext(win);
if (!gl) { logf("GL context: %s", SDL_GetError()); return 1; } if (!gl) { logf("GL context: %s", SDL_GetError()); return 1; }
SDL_GL_SetSwapInterval(opt.headless ? 0 : 1); SDL_GL_SetSwapInterval(opt.headless ? 0 : 1);
@ -225,16 +257,31 @@ int main(int argc, char** argv) {
} }
logf("GL %s / %s", (const char*)glGetString(GL_VERSION), (const char*)glGetString(GL_RENDERER)); logf("GL %s / %s", (const char*)glGetString(GL_VERSION), (const char*)glGetString(GL_RENDERER));
auto surface_size_for_window = [&](int& sw, int& sh) {
int ww, wh, pw, ph;
SDL_GetWindowSize(win, &ww, &wh);
SDL_GetWindowSizeInPixels(win, &pw, &ph);
float k = opt.surface_scale > 0 ? opt.surface_scale : (float)pw / std::max(ww, 1);
sw = std::max(480, (int)(ww * k + 0.5f)) & ~1;
sh = std::max(320, (int)(wh * k + 0.5f)) & ~1;
};
surface_size_for_window(W, H);
g_screen_w = W;
g_screen_h = H;
browser_attach(win, W, H); browser_attach(win, W, H);
// Offscreen surface that the game sees as the Android window. // Offscreen surface that the game sees as the Android window.
GLuint fbo, color, depth; GLuint fbo, color, depth;
glGenFramebuffersEXT(1, &fbo); glGenFramebuffersEXT(1, &fbo);
glGenRenderbuffersEXT(1, &color); glGenRenderbuffersEXT(1, &color);
glGenRenderbuffersEXT(1, &depth); glGenRenderbuffersEXT(1, &depth);
auto alloc_surface = [&](int w, int h) {
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, color); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, color);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, W, H); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, w, h);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, W, H); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, w, h);
};
alloc_surface(W, H);
logf("surface %dx%d", W, H);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, color); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, color);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth);
@ -277,7 +324,7 @@ int main(int argc, char** argv) {
uint32_t env = jni_env(); uint32_t env = jni_env();
auto cls = [](const char* n) { return jclass(n); }; auto cls = [](const char* n) { return jclass(n); };
uint32_t touchCls = cls("com/ea/blast/TouchSurfaceAndroid"); uint32_t touchCls = cls("com/ea/blast/TouchSurfaceAndroid");
uint32_t kDown = 0, kUp = 0, kMove = 0, kTouch = 0; uint32_t kDown = 0, kUp = 0, kMove = 0, kTouch = 0, kKeyboard = 0;
ui.run([&] { ui.run([&] {
g_lib = load_elf(g_game_dir + "/apk/lib/armeabi/libSpyMouse.so", LIB_BASE); g_lib = load_elf(g_game_dir + "/apk/lib/armeabi/libSpyMouse.so", LIB_BASE);
for (uint32_t fn : g_lib.init_array) { for (uint32_t fn : g_lib.init_array) {
@ -292,6 +339,7 @@ int main(int argc, char** argv) {
kUp = call_native("Java_com_ea_blast_TouchSurfaceAndroid_NativeGetIdRawPointerUp", {env, touchCls}); kUp = call_native("Java_com_ea_blast_TouchSurfaceAndroid_NativeGetIdRawPointerUp", {env, touchCls});
kMove = call_native("Java_com_ea_blast_TouchSurfaceAndroid_NativeGetIdRawPointerMove", {env, touchCls}); kMove = call_native("Java_com_ea_blast_TouchSurfaceAndroid_NativeGetIdRawPointerMove", {env, touchCls});
kTouch = call_native("Java_com_ea_blast_ModuleCatalog_NativeGetModuleTypeIdTouchScreen", {env, cls("com/ea/blast/ModuleCatalog")}); kTouch = call_native("Java_com_ea_blast_ModuleCatalog_NativeGetModuleTypeIdTouchScreen", {env, cls("com/ea/blast/ModuleCatalog")});
kKeyboard = call_native("Java_com_ea_blast_ModuleCatalog_NativeGetModuleTypeIdPhysicalKeyboard", {env, cls("com/ea/blast/ModuleCatalog")});
g_orientation_normal = call_native("Java_com_ea_blast_DisplayAndroidDelegate_NativeGetOrientationNormal", {env, cls("com/ea/blast/DisplayAndroidDelegate")}); g_orientation_normal = call_native("Java_com_ea_blast_DisplayAndroidDelegate_NativeGetOrientationNormal", {env, cls("com/ea/blast/DisplayAndroidDelegate")});
logf("touch ids down=%u up=%u move=%u module=%u", kDown, kUp, kMove, kTouch); logf("touch ids down=%u up=%u move=%u module=%u", kDown, kUp, kMove, kTouch);
@ -340,8 +388,34 @@ int main(int argc, char** argv) {
std::this_thread::sleep_for(std::chrono::milliseconds(12)); // TouchSurfaceAndroid sleeps 12 ms per event std::this_thread::sleep_for(std::chrono::milliseconds(12)); // TouchSurfaceAndroid sleeps 12 ms per event
}); });
}; };
// Physical keyboard, as PhysicalKeyboardAndroid forwards it (key down without repeats, key up, character).
uint32_t keyboard_obj = jobject("com/ea/blast/PhysicalKeyboardAndroid");
auto send_key = [&](int android_key, bool down, bool alt, uint32_t unicode) {
ui.post([=] {
if (down) {
call_native("Java_com_ea_blast_KeyboardAndroid_NativeOnKeyDown", {env, keyboard_obj, kKeyboard, (uint32_t)android_key, alt ? 1u : 0u});
} else {
call_native("Java_com_ea_blast_KeyboardAndroid_NativeOnKeyUp", {env, keyboard_obj, kKeyboard, (uint32_t)android_key, alt ? 1u : 0u});
if (unicode) call_native("Java_com_ea_blast_KeyboardAndroid_NativeOnCharacter", {env, keyboard_obj, kKeyboard, unicode});
}
});
};
uint32_t draw = native("Java_com_ea_blast_AndroidRenderer_NativeOnDrawFrame"); uint32_t draw = native("Java_com_ea_blast_AndroidRenderer_NativeOnDrawFrame");
// Window resize -> new surface size, reported like an Android surface change once the size settles.
int pending_w = 0, pending_h = 0;
Uint64 resize_at = 0;
auto apply_resize = [&](int w, int h) {
if (w == W && h == H) return;
W = w; H = h;
g_screen_w = W; g_screen_h = H;
alloc_surface(W, H);
browser_attach(win, W, H);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
logf("surface resized to %dx%d", W, H);
call_native("Java_com_ea_blast_AndroidRenderer_NativeOnSurfaceChanged", {env, renderer, (uint32_t)W, (uint32_t)H});
};
// Android lifecycle: losing focus pauses the game (it saves and stops music), regaining it resumes. // Android lifecycle: losing focus pauses the game (it saves and stops music), regaining it resumes.
// `paused` is the requested state; rendering keeps going until the UI thread has finished OnPause // `paused` is the requested state; rendering keeps going until the UI thread has finished OnPause
// (the engine waits for one more frame), then stops until resume. // (the engine waits for one more frame), then stops until resume.
@ -389,6 +463,35 @@ int main(int argc, char** argv) {
case SDL_EVENT_WINDOW_FOCUS_GAINED: set_paused(false); break; case SDL_EVENT_WINDOW_FOCUS_GAINED: set_paused(false); break;
case SDL_EVENT_WINDOW_MINIMIZED: set_paused(true); break; case SDL_EVENT_WINDOW_MINIMIZED: set_paused(true); break;
case SDL_EVENT_WINDOW_RESTORED: set_paused(false); break; case SDL_EVENT_WINDOW_RESTORED: set_paused(false); break;
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
case SDL_EVENT_WINDOW_RESIZED:
surface_size_for_window(pending_w, pending_h);
resize_at = SDL_GetTicks() + 150;
break;
case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP: {
bool down = ev.type == SDL_EVENT_KEY_DOWN;
SDL_Keymod mod = ev.key.mod;
// window shortcuts (not sent to the game)
if (down && ((ev.key.key == SDLK_F && (mod & SDL_KMOD_GUI)) || ev.key.key == SDLK_F11 ||
(ev.key.key == SDLK_RETURN && (mod & SDL_KMOD_ALT)))) {
bool fs = SDL_GetWindowFlags(win) & SDL_WINDOW_FULLSCREEN;
SDL_SetWindowFullscreen(win, !fs);
break;
}
if (down && ev.key.key == SDLK_W && (mod & SDL_KMOD_GUI)) { g_quit = true; break; }
if (mod & SDL_KMOD_GUI) break;
if (paused || (down && ev.key.repeat)) break;
int code = android_keycode(ev.key.key);
if (!code) break;
uint32_t ch = 0;
if (!down && ev.key.key >= 32 && ev.key.key < 127) {
ch = (uint32_t)ev.key.key;
if ((mod & SDL_KMOD_SHIFT) && ch >= 'a' && ch <= 'z') ch -= 32;
}
send_key(code, down, mod & SDL_KMOD_ALT, ch);
break;
}
default: break; default: break;
} }
if (paused) continue; if (paused) continue;
@ -398,7 +501,7 @@ int main(int argc, char** argv) {
int ww, wh; int ww, wh;
SDL_GetWindowSize(win, &ww, &wh); SDL_GetWindowSize(win, &ww, &wh);
float scale = std::min(ww / (float)W, wh / (float)H); float scale = std::min(ww / (float)W, wh / (float)H);
float ox = (ww - W * scale) / 2, oy = (wh - H * scale) / 2; float ox = (ww - W * scale) / 2, oy = (wh - H * scale) / 2; // non-zero only while a resize is pending
float mx = ev.type == SDL_EVENT_MOUSE_MOTION ? ev.motion.x : ev.button.x; float mx = ev.type == SDL_EVENT_MOUSE_MOTION ? ev.motion.x : ev.button.x;
float my = ev.type == SDL_EVENT_MOUSE_MOTION ? ev.motion.y : ev.button.y; float my = ev.type == SDL_EVENT_MOUSE_MOTION ? ev.motion.y : ev.button.y;
float x = std::clamp((mx - ox) / scale, 0.f, (float)W - 1), y = std::clamp((my - oy) / scale, 0.f, (float)H - 1); float x = std::clamp((mx - ox) / scale, 0.f, (float)W - 1), y = std::clamp((my - oy) / scale, 0.f, (float)H - 1);
@ -408,6 +511,7 @@ int main(int argc, char** argv) {
send_touch(kind, x, y); send_touch(kind, x, y);
} }
} }
if (resize_at && SDL_GetTicks() >= resize_at) { resize_at = 0; apply_resize(pending_w, pending_h); }
for (auto& e : script) if (e.frame == frame) { logf("script touch %u at %.0f,%.0f", e.kind, e.x, e.y); send_touch(e.kind, e.x, e.y); } for (auto& e : script) if (e.frame == frame) { logf("script touch %u at %.0f,%.0f", e.kind, e.x, e.y); send_touch(e.kind, e.x, e.y); }
// control commands // control commands
@ -427,6 +531,23 @@ int main(int argc, char** argv) {
cmds.push_back({"down", {c.a[0], c.a[1]}, ""}); cmds.push_back({"down", {c.a[0], c.a[1]}, ""});
cmds.push_back({"wait", {3}, ""}); cmds.push_back({"wait", {3}, ""});
cmds.push_back({"up", {c.a[0], c.a[1]}, ""}); cmds.push_back({"up", {c.a[0], c.a[1]}, ""});
} else if (c.op == "click" && c.a.size() >= 2) {
cmds.push_back({"mdown", {c.a[0], c.a[1]}, ""});
cmds.push_back({"wait", {3}, ""});
cmds.push_back({"mup", {c.a[0], c.a[1]}, ""});
} else if (c.op == "mdrag" && c.a.size() >= 4) {
int n = c.a.size() >= 5 ? (int)c.a[4] : 20;
cmds.push_back({"mdown", {c.a[0], c.a[1]}, ""});
for (int k = 1; k <= n; k++) {
float t = k / (float)n;
cmds.push_back({"wait", {1}, ""});
cmds.push_back({"mmove", {c.a[0] + (c.a[2] - c.a[0]) * t, c.a[1] + (c.a[3] - c.a[1]) * t}, ""});
}
cmds.push_back({"mup", {c.a[2], c.a[3]}, ""});
} else if (c.op == "press" && !c.a.empty()) {
cmds.push_back({"kdown", {c.a[0]}, ""});
cmds.push_back({"wait", {3}, ""});
cmds.push_back({"kup", {c.a[0]}, ""});
} else if (c.op == "drag" && c.a.size() >= 4) { } else if (c.op == "drag" && c.a.size() >= 4) {
int n = c.a.size() >= 5 ? (int)c.a[4] : 20; int n = c.a.size() >= 5 ? (int)c.a[4] : 20;
cmds.push_back({"down", {c.a[0], c.a[1]}, ""}); cmds.push_back({"down", {c.a[0], c.a[1]}, ""});
@ -451,6 +572,32 @@ int main(int argc, char** argv) {
else if (c.op == "move") send_touch(kMove, c.a[0], c.a[1]); else if (c.op == "move") send_touch(kMove, c.a[0], c.a[1]);
else if (c.op == "wait") { wait_until = frame + (c.a.empty() ? 1 : (int)c.a[0]); } else if (c.op == "wait") { wait_until = frame + (c.a.empty() ? 1 : (int)c.a[0]); }
else if (c.op == "shot") { pending_shot = ctl + "/" + c.name + ".png"; } else if (c.op == "shot") { pending_shot = ctl + "/" + c.name + ".png"; }
// real input path: synthesized SDL events in window coordinates (points), mapped like a real mouse
else if ((c.op == "mdown" || c.op == "mup" || c.op == "mmove") && c.a.size() >= 2) {
SDL_Event e{};
if (c.op == "mmove") {
e.type = SDL_EVENT_MOUSE_MOTION;
e.motion.windowID = SDL_GetWindowID(win);
e.motion.x = c.a[0]; e.motion.y = c.a[1];
} else {
e.type = c.op == "mdown" ? SDL_EVENT_MOUSE_BUTTON_DOWN : SDL_EVENT_MOUSE_BUTTON_UP;
e.button.windowID = SDL_GetWindowID(win);
e.button.button = SDL_BUTTON_LEFT;
e.button.down = c.op == "mdown";
e.button.x = c.a[0]; e.button.y = c.a[1];
}
SDL_PushEvent(&e);
}
else if ((c.op == "kdown" || c.op == "kup") && !c.a.empty()) {
SDL_Event e{};
e.type = c.op == "kdown" ? SDL_EVENT_KEY_DOWN : SDL_EVENT_KEY_UP;
e.key.windowID = SDL_GetWindowID(win);
e.key.key = (SDL_Keycode)c.a[0];
e.key.down = c.op == "kdown";
SDL_PushEvent(&e);
}
else if (c.op == "key" && !c.a.empty()) { send_key((int)c.a[0], true, false, 0); send_key((int)c.a[0], false, false, 0); }
else if (c.op == "resize" && c.a.size() >= 2) { SDL_SetWindowSize(win, (int)c.a[0], (int)c.a[1]); }
else if (c.op == "pause") set_paused(true); else if (c.op == "pause") set_paused(true);
else if (c.op == "resume") set_paused(false); else if (c.op == "resume") set_paused(false);
else if (c.op == "quit") g_quit = true; else if (c.op == "quit") g_quit = true;