{"id":13480758,"url":"https://github.com/MJx0/InputMsgCapture","last_synced_at":"2025-03-27T11:30:52.936Z","repository":{"id":213096745,"uuid":"733009990","full_name":"MJx0/InputMsgCapture","owner":"MJx0","description":"Capture input events of any android application","archived":false,"fork":false,"pushed_at":"2024-06-06T17:21:38.000Z","size":44,"stargazers_count":34,"open_issues_count":0,"forks_count":11,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-30T14:42:33.683Z","etag":null,"topics":["android","imgui","input","reverse-engineering"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MJx0.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-18T11:08:02.000Z","updated_at":"2024-09-10T04:08:13.000Z","dependencies_parsed_at":"2024-10-30T14:34:42.049Z","dependency_job_id":null,"html_url":"https://github.com/MJx0/InputMsgCapture","commit_stats":null,"previous_names":["mjx0/inputmsgcapture"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MJx0%2FInputMsgCapture","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MJx0%2FInputMsgCapture/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MJx0%2FInputMsgCapture/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MJx0%2FInputMsgCapture/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MJx0","download_url":"https://codeload.github.com/MJx0/InputMsgCapture/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245835933,"owners_count":20680295,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","imgui","input","reverse-engineering"],"created_at":"2024-07-31T17:00:44.667Z","updated_at":"2025-03-27T11:30:52.627Z","avatar_url":"https://github.com/MJx0.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"# InputMsgCapture\n\nCapture input events of any android application by scanning malloc memory for InputConsumer instance then keep reading the InputMessage variable which receives inputs from InputPublisher paired socket.\n\n![image info](./log.png)\n\n\u003ch2\u003e Support: \u003c/h2\u003e\n\n- [x] Android 5.0  ~ 14\n- [x] ABI arm, arm64, x86, x86_64\n- [x] Compatible with imgui\n\n\u003ch2\u003e Notes: \u003c/h2\u003e\n\n- The scan speed depends on malloc mapped memory if it's named or not, some devices uses \"[anon:libc_malloc]\" or \"[anon:scudo_primary]\" which will speed up the scan, however some devices use unnamed memory which then every unnamed memory will be scanned making it much slower\n- Each activity will have an InputConsumer instance\n- Make sure to use the correct activity, you can use multiple at once. For most games, the activity to use is the main one unless it's a splash activity then it should be ignored\n\n\u003ch2\u003e How to use: \u003c/h2\u003e\n\n```cpp\n#include \"iMsgCapture/iMsgCapture.h\"\n\n// set a callback for new input events\niMsgCapture::instance().setCallback([](iMsgEvent* iMsg) -\u003e void\n{\n    // show/hide menu with volume buttons\n    if (iMsg-\u003eisKeyEvent())\n    {\n        if (iMsg-\u003egetKey()-\u003egetIsDown(AKEYCODE_VOLUME_DOWN))\n            bShowMenu = false;\n        else if (iMsg-\u003egetKey()-\u003egetIsDown(AKEYCODE_VOLUME_UP))\n            bShowMenu = true;\n    }\n\n    // handle imgui input\n    if (bImGuiInit \u0026\u0026 bShowMenu)\n        ImGui_ImplAndroid_HandleInputMsg(iMsg);\n\n    // logging\n\n    iMSG_LOGI(\"received input event of type %d\", iMsg-\u003etype());\n\n    if (iMsg-\u003eisKeyEvent()) {\n        const iKeyEvent *keyEvent = iMsg-\u003egetKey();\n        iMSG_LOGI(\"keyCode %d\", keyEvent-\u003egetKeyCode());\n        iMSG_LOGI(\"scanCode %d\", keyEvent-\u003egetScanCode());\n        iMSG_LOGI(\"repeatCount %d\", keyEvent-\u003egetRepeatCount());\n        iMSG_LOGI(\"metaState %d\", keyEvent-\u003egetMetaState());\n        iMSG_LOGI(\"action %s\", keyEvent-\u003egetActionString().c_str());\n        iMSG_LOGI(\"source %s\", keyEvent-\u003egetSourceString().c_str());\n    } else if (iMsg-\u003eisMotionEvent()) {\n        const iMotionEvent *motionEvent = iMsg-\u003egetMotion();\n        iMSG_LOGI(\"action %s\", motionEvent-\u003egetActionString().c_str());\n        iMSG_LOGI(\"source %s\", iMsg-\u003egetSourceString().c_str());\n        iMSG_LOGI(\"OffsetX=%.2f, OffsetY=%.2f\", motionEvent-\u003egetOffsetX(), motionEvent-\u003egetOffsetY());\n        iMSG_LOGI(\"PrecisionX=%.2f, PrecisionY=%.2f\", motionEvent-\u003egetPrecisionX(), motionEvent-\u003egetPrecisionY());\n        iMSG_LOGI(\"actionIndex %d\", motionEvent-\u003egetActionIndex());\n        iMSG_LOGI(\"downTime %\" PRId64, motionEvent-\u003egetDownTime());\n\n        uint32_t pointerCount = motionEvent-\u003egetPointerCount();\n        iMSG_LOGI(\"pointerCount %d\", pointerCount);\n        for (uint32_t i = 0; i \u003c pointerCount; i++) {\n            iMSG_LOGI(\"actionId[%d] %d\", i, motionEvent-\u003egetActionId(i));\n            iMSG_LOGI(\"toolType[%d] %s\", i, motionEvent-\u003egetToolTypeString(i).c_str());\n            iMSG_LOGI(\"Orientation[%d] %f\", i, motionEvent-\u003egetOrientation(i));\n            iMSG_LOGI(\"X[%d]=%.2f, Y[%d]=%.2f\", i, motionEvent-\u003egetX(i), i, motionEvent-\u003egetY(i));\n            iMSG_LOGI(\"RawX[%d]=%.2f, RawY[%d]=%.2f\", i, motionEvent-\u003egetRawX(i), i, motionEvent-\u003egetRawY(i));\n        }\n    }\n\n    iMSG_LOGI(\"===============================\");\n});\n\n// set an update interval in microsecnds\niMsgCapture::instance().setUpdateInterval(1000);\n\n// run thread\n// each activity will have a consumer instance\n// make sure to use the correct activity, you can use multiple at once\n// For most games, the activity to use is the main one unless it's a splash activity then it should be ignored\niMsgCapture::instance().runThread(/* activity */ {\"com.epicgames.ue4.GameActivity\"}, /* retry on failure */ true, /* retry timer in seconds */ 1);\n```\n\n\u003ch2\u003e Scaling touch: \u003c/h2\u003e\nWhen surface width \u0026 height are scaled and do not match real device, then we need to setup ratio.\n\nExample with OpenGLES surface:\n\n```cpp\n// This should be the real device width \u0026 height\nint iDeviceWidth = 1920, iDeviceHeight = 1080;\n\nint iDisplayWidth = 0, iDisplayHeight = 0;\neglQuerySurface(dpy, surface, EGL_WIDTH, \u0026iDisplayWidth);\neglQuerySurface(dpy, surface, EGL_HEIGHT, \u0026iDisplayHeight);\n\nif (iDeviceWidth != iDisplayWidth) {\n    iMsgCapture::instance().setTouchRatioX(float(iDisplayWidth) / float(iDeviceWidth));\n}\nif (iDeviceHeight != iDisplayHeight) {\n    iMsgCapture::instance().setTouchRatioY(float(iDisplayHeight) / float(iDeviceHeight));\n}\n```\n\n\u003ch2\u003eimgui: \u003c/h2\u003e\nin imgui_impl_android.h:\n\n```cpp\nint32_t ImGui_ImplAndroid_HandleInputMsg(class iMsgEvent* iMsg);\n```\n\nin imgui_impl_android.cpp:\n\n```cpp\n#include \"iMsgCapture/iMsgEvent.h\"\nint32_t ImGui_ImplAndroid_HandleInputMsg(iMsgEvent* iMsg)\n{\n    ImGuiIO\u0026 io = ImGui::GetIO();\n    if (iMsg-\u003eisKeyEvent())\n    {\n        const iKeyEvent *keyEvent = iMsg-\u003egetKey();\n        int32_t event_key_code = keyEvent-\u003egetKeyCode();\n        int32_t event_scan_code = keyEvent-\u003egetScanCode();\n        int32_t event_action = keyEvent-\u003egetAction();\n        int32_t event_meta_state = keyEvent-\u003egetMetaState();\n\n        io.AddKeyEvent(ImGuiMod_Ctrl,  (event_meta_state \u0026 AMETA_CTRL_ON)  != 0);\n        io.AddKeyEvent(ImGuiMod_Shift, (event_meta_state \u0026 AMETA_SHIFT_ON) != 0);\n        io.AddKeyEvent(ImGuiMod_Alt,   (event_meta_state \u0026 AMETA_ALT_ON)   != 0);\n        io.AddKeyEvent(ImGuiMod_Super, (event_meta_state \u0026 AMETA_META_ON)  != 0);\n\n        switch (event_action)\n        {\n        case AKEY_EVENT_ACTION_DOWN:\n        case AKEY_EVENT_ACTION_UP:\n        {\n            ImGuiKey key = ImGui_ImplAndroid_KeyCodeToImGuiKey(event_key_code);\n            if (key != ImGuiKey_None \u0026\u0026 (event_action == AKEY_EVENT_ACTION_DOWN || event_action == AKEY_EVENT_ACTION_UP))\n            {\n                io.AddKeyEvent(key, event_action == AKEY_EVENT_ACTION_DOWN);\n                io.SetKeyEventNativeData(key, event_key_code, event_scan_code);\n            }\n\n            break;\n        }\n        default:\n            break;\n        }\n    }\n    else if (iMsg-\u003eisMotionEvent())\n    {\n        const iMotionEvent *motionEvent = iMsg-\u003egetMotion();\n        int32_t event_action = motionEvent-\u003egetActionMasked();\n        int32_t event_pointer_index = motionEvent-\u003egetActionIndex();\n        int32_t tool_type = motionEvent-\u003egetToolType(event_pointer_index);\n\n        switch (tool_type)\n        {\n        case AMOTION_EVENT_TOOL_TYPE_MOUSE:\n            io.AddMouseSourceEvent(ImGuiMouseSource_Mouse);\n            break;\n        case AMOTION_EVENT_TOOL_TYPE_STYLUS:\n        case AMOTION_EVENT_TOOL_TYPE_ERASER:\n            io.AddMouseSourceEvent(ImGuiMouseSource_Pen);\n            break;\n        case AMOTION_EVENT_TOOL_TYPE_FINGER:\n        default:\n            io.AddMouseSourceEvent(ImGuiMouseSource_TouchScreen);\n            break;\n        }\n\n        switch (event_action)\n        {\n        case AMOTION_EVENT_ACTION_DOWN:\n        case AMOTION_EVENT_ACTION_UP:\n            if(tool_type == AMOTION_EVENT_TOOL_TYPE_FINGER || tool_type == AMOTION_EVENT_TOOL_TYPE_UNKNOWN)\n            {\n                io.AddMousePosEvent(motionEvent-\u003egetX(event_pointer_index), motionEvent-\u003egetY(event_pointer_index));\n                io.AddMouseButtonEvent(0, event_action == AMOTION_EVENT_ACTION_DOWN);\n            }\n            break;\n        case AMOTION_EVENT_ACTION_BUTTON_PRESS:\n        case AMOTION_EVENT_ACTION_BUTTON_RELEASE:\n            {\n                int32_t button_state = motionEvent-\u003egetButtonState();\n                io.AddMouseButtonEvent(0, (button_state \u0026 AMOTION_EVENT_BUTTON_PRIMARY) != 0);\n                io.AddMouseButtonEvent(1, (button_state \u0026 AMOTION_EVENT_BUTTON_SECONDARY) != 0);\n                io.AddMouseButtonEvent(2, (button_state \u0026 AMOTION_EVENT_BUTTON_TERTIARY) != 0);\n            }\n            break;\n        case AMOTION_EVENT_ACTION_HOVER_MOVE:\n        case AMOTION_EVENT_ACTION_MOVE:\n            io.AddMousePosEvent(motionEvent-\u003egetX(event_pointer_index), motionEvent-\u003egetY(event_pointer_index));\n            break;\n        case AMOTION_EVENT_ACTION_SCROLL:\n            io.AddMouseWheelEvent(motionEvent-\u003egetAxisValue(event_pointer_index, AMOTION_EVENT_AXIS_HSCROLL), motionEvent-\u003egetAxisValue(event_pointer_index, AMOTION_EVENT_AXIS_VSCROLL));\n            break;\n        default:\n            break;\n        }\n        return 1;\n    }\n\n    return 0;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMJx0%2FInputMsgCapture","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMJx0%2FInputMsgCapture","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMJx0%2FInputMsgCapture/lists"}