Input from stdin

Processing has provided a very good way to introduce students to programming (and to OO), and the immediate gratification of visual output is very effective.
However, the lack of keyboard input is very frustrating!
(This often forces me into very-distracting subterfuges in order to teach students how to write simple algorithms to process keyboard input!)

After years of frustration with this, I finally broke down and created some code to allow keyboard input in real time (rather than restricting input to prepared files).

My solution now allows students to write sketches that solicit user input, but this approach is not very slick and somewhat “klunky” (since you have to write code that detects missing input and prompts the user to supply it, while suspending the draw() method).

Therefore, I welcome comments and suggestions.

Here is a link to a code example that accepts keyboard input for missing values.
When the program begins, the user must input (x,y) coordinates.
If the ‘x’ or ‘w’ or ‘c’ key is pressed, values become undefined (negative) for porition, size, or color (respectively), and user input is solicited.

Yeah, it’s very klunky (and the coding is a bit tedious and ugly), so I am very open to a better solution (while preserving keyPressed() method for other things).

?where? pls. edit your post

I’ve got 2 “.java” sorta library files for it! Both based on JOptionPane: :smiley_cat:

“Keyboard Input Library” is more sophisticated. But it isn’t cross-mode compatible w/ Pjs:

“WindowJS” is simpler. But b/c it emulates some of JS’ API (mostly alert(), confirm(), prompt(), etc.), a sketch that relies on it can be run online via Pjs: :star_struck:

Check out a sample sketch using “WindowJS” online by copying & pasting the link below in another tab: :running_man:$Bjf6i21oXBw