
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
contro-max
Advanced tools
The package is ESM
e.key
instead of e.code
so your app/game won't work with different layoutsalt+tab
MCRAFT.FUN is using this module!
event.code
Contro Max is a framework rather than library. The main goal is to give easiest way for handling all possible input types in web.
contro-max
doesn't share concept of being flexible and doesn't provide abstractions that would allow you to craft custom inputs (but maybe you shouldn't?). Instead, we suggest should define so called schema of all commands
First of all, you need to create controls schema for your app/game:
export const controls = createControlsSchema({
core: {
openInventory: ["KeyE", "LB"] // Can also use mouse input like Mouse1 insdead of KeyE
}
});
As you can see, schema is the object with event names and arrays: [KeyboardKey, GamepadButton]
.
Also, you can add options for the event (options we'll cover later):
{ openInventory: ["KeyE", "LB", { disabled: true, /* other options */ }] }
If your event doesn't have binding for Gamepad, just don't pass anything:
{ sayHello: ["Comma"] } // or
{ sayHello: ["Comma", { /* event specific options */ }] }
If your command doesn't have default keyboard binding:
{ sayHello: null }
// or if you have to specify options
{ sayHello: [null, { /* event specific options */ }] }
// with gamepad button specified
{ sayHello: [null, "LB", { /* event specific options */ }] }
Okay, when we defined schema, you can use it anywhere in your app for executing/listening to commands
There are two ways of triggering:
controls.trigger()
// this will fire trigger and then release events with the given command
window.dispatchEvent(new KeyboardEvent("keydown", {
code: "Escape"
}))
controls.trigger("openInventory");
Without global state:
const DisplayControls: React.FC = () => {
const { } = useKeyboard(["space", "arrowKeys"], { preventDefault: true })
}
(experimental)
Contro max would fire events only when it actually sees the canvas.
Here is how it works:
You specify canvasElem
as an option for your createControlsSchema
.
If you don't specify this feature won't and events will always fire skipping the check.
createControlsSchema
start watching for the changes of document.body
. When it detects change of its children (some root element is added or removed), the check is performed that element in center of the screen is canvasElem
.
But with this approach you must ensure that all modals and menus are being showed in root of DOM (document.body
). Most UI libraries does this for you (e.g. MUI).
Contro max doesn't rely on document.activeElement
and instead would unlock controls only when
TODO
Gamepads like this the most probably won't work at all. (use tester above) But if you're under Windows and OS sees gamepad as gamepad (not keyboard) or can remap buttons using TocaEdit in pair with vJoy, but it's quite not easy to do so I'll post instructions later here.
FAQs
Game controls done in the best possible way!
The npm package contro-max receives a total of 57 weekly downloads. As such, contro-max popularity was classified as not popular.
We found that contro-max demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.