This file is the configuration guide in creating the useAllKeysPress
demos, these examples are:
1. Single key
const avoPress = useAllKeysPress({ userKeys: "a" });
const waterPress = useAllKeysPress({ userKeys: "w" });
const duckPress = useAllKeysPress({ userKeys: "d" });
const foxPress = useAllKeysPress({ userKeys: "f" });
const inputs = [
{ input: avoPress, key: "a", symbol: "๐ฅ" },
{ input: waterPress, key: "w", symbol: "๐คฝ" },
{ input: duckPress, key: "d", symbol: "๐ฆ" },
{ input: foxPress, key: "f", symbol: "๐ฆ" }
];
// Aids in the detection of the first key pressed in.
const anyKeyPressed = inputs.some((item) => item.input === true);
<Title
heading={"Single key usage"}
subtext={"Press the key and see."}
/>
<UseAllKeypad
inputs={inputs}
/>
<Screen
activate={anyKeyPressed}
input={inputs}
></Screen>
<UserOutput
items={inputs}
/>
// create a ref to attach to the element that will have focus.
const input = useRef(null)
const upPress = useAllKeysPress({ userKeys: "ArrowUp", ref: input });
const downPress = useAllKeysPress({ userKeys: "ArrowDown", ref: input });
const inputs = [
{ input: upPress, key: "ArrowUp", symbol: "๐ค" },
{ input: downPress, key: "ArrowDown", symbol: "๐คฎ" }
];
// Aids in the detection of the first key pressed in.
const anyKeyPressed = inputs.some((item) => item.input === true);
<Title
heading={"Key on Focused Element"}
subtext={"Press the key and see."}
/>
<UseAllKeypad
inputs={inputs}
/>
<Screen
activate={anyKeyPressed}
input={inputs}
>
// element to be referenced on focus.
<UseAllInput ref={input} />
</Screen>
<UserOutput
items={inputs}
/>
const avoPress = useAllKeysPress({ userKeys: "a" });
const waterPress = useAllKeysPress({ userKeys: "w" });
const duckPress = useAllKeysPress({ userKeys: "d" });
const foxPress = useAllKeysPress({ userKeys: "f" });
// this variable represents will when all are pressed
const combinePress = useAllKeysPress({ userKeys: ["a", "w", "d", "f"] });
const inputs = [
{ input: avoPress, key: "a", symbol: "๐ฅ" },
{ input: waterPress, key: "w", symbol: "๐คฝ" },
{ input: duckPress, key: "d", symbol: "๐ฆ" },
{ input: foxPress, key: "f", symbol: "๐ฆ" }
];
// Aids in the detection of the first key pressed in.
const anyKeyPressed = inputs.some((item) => item.input === true);
<Title
heading={"Multiple keys"}
subtext={"Press the keys and see."}
/>
<UseAllKeypad
inputs={inputs}
type={"multi"}
/>
<Screen
activate={anyKeyPressed}
input={inputs}
></Screen>
<UserOutput
items={inputs}
combine={combinePress}
/>
const akeyPress = useAllKeysPress({ userKeys: "a" });
const bkeyPress = useAllKeysPress({ userKeys: "b" });
const ckeyPress = useAllKeysPress({ userKeys: "c" });
// this variable represents will when all are pressed in order
const combinePress = useAllKeysPress({ userKeys: ["a", "b", "c"], order: true });
const inputs = [
{ input: akeyPress, key: "a"},
{ input: bkeyPress, key: "b"},
{ input: ckeyPress, key: "c"},
];
// Aids in the detection of the first key pressed in.
const anyKeyPressed = inputs.some((item) => item.input === true);
<Title
heading={"Multiple keys in order"}
subtext={"Press the keys and see."}
/>
<UseAllKeypad
inputs={inputs}
type={"multi"}
/>
<Screen
activate={anyKeyPressed}
input={inputs}
combine={combinePress}
type={"jackson"}
message={"All you gotto do is repeat after me!!"}
></Screen>
<UserOutput
items={inputs}
combine={combinePress}
/>