pxt-calliope/sim/state/buttonpair.ts

32 lines
1.2 KiB
TypeScript
Raw Normal View History

2016-08-30 20:51:32 +02:00
namespace pxsim.input {
2021-11-25 17:27:39 +01:00
export function onButtonEvent(button: number, buttonEvent: number, handler: RefAction): void {
let b = board().buttonPairState;
if (button == b.props.ID_BUTTON_AB && !b.usesButtonAB) {
b.usesButtonAB = true;
runtime.queueDisplayUpdate();
}
pxtcore.registerWithDal(button, buttonEvent, handler);
}
// Deprecated
2016-08-30 20:51:32 +02:00
export function onButtonPressed(button: number, handler: RefAction): void {
let b = board().buttonPairState;
if (button == b.props.ID_BUTTON_AB && !b.usesButtonAB) {
2016-08-30 20:51:32 +02:00
b.usesButtonAB = true;
runtime.queueDisplayUpdate();
}
2020-08-19 22:03:58 +02:00
pxtcore.registerWithDal(button, DAL.MICROBIT_BUTTON_EVT_CLICK, handler);
2016-08-30 20:51:32 +02:00
}
2020-08-19 22:03:58 +02:00
2016-08-30 20:51:32 +02:00
export function buttonIsPressed(button: number): boolean {
let b = board().buttonPairState;
if (button == b.abBtn.id && !b.usesButtonAB) {
2016-08-30 20:51:32 +02:00
b.usesButtonAB = true;
runtime.queueDisplayUpdate();
}
if (button == b.aBtn.id) return b.aBtn.pressed;
if (button == b.bBtn.id) return b.bBtn.pressed;
2016-08-30 20:51:32 +02:00
return b.abBtn.pressed || (b.aBtn.pressed && b.bBtn.pressed);
}
}