2016-08-30 20:51:32 +02:00
|
|
|
namespace pxsim.input {
|
|
|
|
export function onButtonPressed(button: number, handler: RefAction): void {
|
|
|
|
let b = board().buttonPairState;
|
2016-09-10 07:56:26 +02:00
|
|
|
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;
|
2016-09-10 07:56:26 +02:00
|
|
|
if (button == b.abBtn.id && !b.usesButtonAB) {
|
2016-08-30 20:51:32 +02:00
|
|
|
b.usesButtonAB = true;
|
|
|
|
runtime.queueDisplayUpdate();
|
|
|
|
}
|
2016-09-10 07:56:26 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|