2016-08-30 20:51:32 +02:00
|
|
|
namespace pxsim.input {
|
2022-03-22 17:36:19 +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;
|
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();
|
|
|
|
}
|
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;
|
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);
|
|
|
|
}
|
|
|
|
}
|