4 ms·
One of my favorites... https://web.stanford.edu/class/archive/cs/cs103/cs103.1142/button-fsm/ https://web.stanford.edu/class/archive/cs/cs103/cs103.1142/b...
by latchkey 2y ago
One of my favorites...
https://web.stanford.edu/class/archive/cs/cs103/cs103.1142/button-fsm/ https://web.stanford.edu/class/archive/cs/cs103/cs103.1142/b...
- lkuty 2y agohow to reach "idle, down" ?
- latchkey 2y agoclick outside of the button and hold down the better question is to ask how to reach "hover pressed"
- atoav 2y agoAs someone who wrote more variants of button handling code than I have fingers (mostly for physical buttons): Buttons can be way more complex than people usually would suspect: - Buttons need to be debounced so you don't trigger 10 presses because the contacts bounce 10 times up and down before they settle to the on state - maybe you want different states and callbacks for single press, while pressed, double press, long press, very long press, release — all of which require to measure time and some thinking (e.g. how can you reach a long press when there is a short press before ?) - how to properly implement key combinations? Does order matter? How would you handle a "both keys at the same time"-scenario if in reality they are many milliseconds apart? And there are always tradeoffs, which is why I had to write more than once variant of the thing (that, and I got better at writing it).