Index of every page on this site: llms.txt
All skills
oahc09 avatar

/cocosair-input-action

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Wire keyboard, mouse, touch and action state; navigate SceneStack pages. Use for focus, held-key resets, session gates, DOM canvas errors or persistent push/pop.

  • 10 files
  • 38.8 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-input-action

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesquick-start.md

≈860 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Derived from the cocosair-input-action skill and its canonical docs/source pointers; reorganized on 2026-10-11. Source annotations below identify repository inputs, not files guaranteed to ship to npm consumers.

Environment: the HTML examples using /build/ require the AIR development server and an existing bundle. In npm applications use the installed package name and the application's own bundler/server; resolve docs and declarations from that package. Do not copy repository URLs into a consumer app. Browser behavior is verified only for explicitly tested snippets and candidates.

Quick Start

<canvas id="GameCanvas"></canvas>
<script type="importmap">
  { "imports": { "cocosair": "/build/cocosair.module.js" } }
</script>
<script type="module">
import {
    createAirApp, Scene, Node, Camera, Vec3, Color, Component,
    input, Input, systemEvent, SystemEvent, KeyCode,
    createActionState, createActionInput, createSessionGate, SceneStack
} from 'cocosair';

const canvas = document.getElementById('GameCanvas'); // must exist before this import
const app = await createAirApp({ canvas });

const scene = new Scene('Main');
const camNode = new Node('Main Camera');
scene.addChild(camNode);
camNode.setPosition(new Vec3(0, 1, 4));
const camera = camNode.addComponent(Camera);
camera.projection = Camera.ProjectionType.PERSPECTIVE;
camera.clearColor = new Color(20, 26, 40, 255);

const gate = createSessionGate();
gate.activate(); // begin a session generation; further gates below honour it

const state = createActionState({
    actions: {
        fire: { sources: [{ backend: 'native', keyCode: KeyCode.KEY_A }] },
        move: {
            mode: 'axis',
            sources: [
                { backend: 'native', keyCode: KeyCode.KEY_W, value: 1 },
                { backend: 'native', keyCode: KeyCode.KEY_S, value: -1 }
            ]
        }
    }
});

const adapter = createActionInput({ state, backend: 'native', canvas, session: gate });
adapter.attach(); // installs listeners; does not steal focus

const stack = new SceneStack(scene, { canvas, maxCachedPages: 4 });
stack.push(() => new Node('Menu'), 'Menu');

let taps = 0;
const onTouchStart = (event) => { taps += 1; /* event.touch is the changed contact */ };
const onMouseDown = (event) => { /* raw mouse, EventMouse */ };
input.on(Input.EventType.TOUCH_START, onTouchStart);
systemEvent.on(SystemEvent.EventType.MOUSE_DOWN, onMouseDown);

class Driver extends Component {
    update() {
        for (const edge of state.consumeTick().transitions) {
            if (edge.action === 'fire' && edge.kind === 'press') {
                stack.push(() => new Node('Level'), 'Level', { transitionMs: 250 });
            }
        }
        camNode.setPosition(0, 1, 4 + state.axis('move'));
    }
}
camNode.addComponent(Driver);

app.run(scene); // async render loop: frames land on later ticks

function teardown() {
    input.off(Input.EventType.TOUCH_START, onTouchStart);
    systemEvent.off(SystemEvent.EventType.MOUSE_DOWN, onMouseDown);
    adapter.dispose(); // reset('dispose') + detach + unbind gate
    stack.dispose();
}
</script>

The Input.EventType.* and SystemEvent.EventType.* enums are the only legal event names; EventMouse, EventTouch and EventKeyboard carry no static event constants of their own (src/cocos/input/input.ts:160, src/cocos/input/system-event.ts:72, src/cocos/input/types/event-enum.ts:277).

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at ed38648. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last month
layer
subsystem
All 1 allowed tools
Read Edit Write Bash
Other metadata
compatibility
Cocos AIR source checkout or installed cocosair.js package. Browser rendering requires WebGL 2; source tooling requires Node.js >=18. Use the host-provided tools and user-authorized workspace.
when_to_use
[
  "map keys, touch or mouse to named actions",
  "keys stop firing while an input has focus",
  "DOM input fails without an explicit canvas",
  "clear held actions after blur or page hiding",
  "preserve page state across push/pop transitions"
]
owns
[
  "native-input",
  "action-state",
  "dom-input",
  "focus-reset",
  "session-gate",
  "scene-stack"
]
not_for
[
  "full scene replacement -> cocosair-application",
  "DOM overlay geometry -> cocosair-graphics-and-dom",
  "node lifecycle and custom events -> cocosair-scene-graph"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "处理原生和 DOM 输入、动作状态、焦点、会话门禁及 SceneStack。用于按键触摸、动作映射、输入阻断或清理问题。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-input-action