flipperdevices / flipperzero-firmware

Flipper Zero firmware source code
https://flipperzero.one
GNU General Public License v3.0
13.03k stars 2.75k forks source link

A JavaScript module for handling a button press #3677

Open tlhunter opened 6 months ago

tlhunter commented 6 months ago

Description of the feature you're suggesting.

I would like to request an API for receiving a single button press. This could be very similar to the existing dialogue API except that it wouldn't clear the screen or display any messages. The developer would be expected to draw to the screen ahead of time.

The API could be very basic:

let buttons = require("buttons");
let result = buttons.waitForButtonPress();
// result in "up", "down", "left", "right", "ok"

Ideally the back button could be caught as well but I understand that it is currently the only way to consistently exit a program and probably shouldn't be caught.

Ideally, assuming the code runs inside of a loop, if the user were to hold down a button continuously then it would just work as expected, triggering the button press with each iteration.

let buttons = require("buttons");
while(true) {
let result = buttons.waitForButtonPress();
// result is read with each iteration even if button remains held
// of course, there is no guaranteed timing...
}

Anything else?

I believe this would unlock a lot of potential games.

skotopes commented 6 months ago

That is Input service bindings

portasynthinca3 commented 3 months ago

Currently working on it as part of the JS GUI module: #3841