inexorabletash / jslogo

Logo in JavaScript
https://calormen.com/jslogo
Other
368 stars 146 forks source link

Add something to be able to react/process keyboard's presses - readchar maybe? #146

Open slavap opened 6 months ago

slavap commented 6 months ago

It is possible to control mouse movement and button clicks, but nothing like that is available for keyboard (at least I see nothing in the docs). Then it will be possible to implement simple interactive games.

bojidar-bg commented 6 months ago

Just to list what other Logo-s are doing:

FMSLogo has KEYBOARDON [ onkeydown commands ] / (KEYBOARDON [ onkeydown commands ] [ onkeyup commands ]) where the commands can make use of KEYBOARDVALUE, which holds the last pressed/released key; plus KEYBOARDOFF that can disable the handler.

NetLogo has buttons which can be configured in a GUI and set to trigger when a certain keyboard key is pressed.

TerrapinLogo has READCHAR which blocks until the next character is inputted as well as KEY which works without blocking.

slavap commented 6 months ago

@bojidar-bg It should work without blocking, KEYBOARDON looks as right thing, KEY is ok as well.

bojidar-bg commented 6 months ago

KEY is most likely not what we want, as it can't handle keyup events. FMSLogo's KEYBOARDON should work nicely though, agreed.

I'd personally also love to also have something like a KEYP/KEY?/KEYDOWNP/KEYDOWN? :key, just to be able to quickly test whether a given key/keycode is currently pressed without having to setup a KEYBOARDON handler and related variables—but, oddly enough, none of the Logos I looked at had a function quite like that... :thinking:

slavap commented 6 months ago

@bojidar-bg KEYP/KEY?/KEYDOWNP/KEYDOWN? :key - is quite a good idea as well and consistent with existing mouse support.