I am sharing here a simple code I developed to handle the user interaction for a simple drawing tool.
The user can draw points dragging the mouse, or lines, if pressing SHIFT at the beginning of the drag. The cool thing is that lines are drawn dynamically, until the user releases the mouse, with the previous drawing history kept intact.
This is the link to the GitHub repository for this sketch: I hope it can serve you as a convenience to add to your project. Enjoy !