pxt-calliope/sim/state/buttonpair.ts

22 lines
821 B
TypeScript
Raw Normal View History

2016-08-30 20:51:32 +02:00
namespace pxsim.input {
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();
}
2016-09-01 14:06:03 +02:00
pxtcore.registerWithDal(button, DAL.MICROBIT_BUTTON_EVT_CLICK, handler);
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);
}
}