This is a quick and fairly lightweight abstraction to get the mouse coordinates on click and drag motion. Three different modes determine the behavior for when the mouse leaves the click area. It works in Pure Data vanilla without any external.
Type [xy 500 300 1] to create a 500 x 300 pixel area in mode 1. See help file for details.
How it works:
A rectangle scalar of the size of the click area, a one pixel scalar and two graphical arrays are placed on top of each other. The second array has an inverted y-range. Both arrays are set to zero. On click both arrays jump to the respective y-value at x-position. When the rectangle scalar receives the click, it reads the x and y values from the first array. If y is zero, it takes the x value from the second array. Now we have x and y for the click.
The arrays are immediately reset to zero and the pixel scalar is placed to where the mouse is, so that it gets the grab. From there on x and y positions are read from the pixel scalar when its struct sends a change event. That's it.
Some more tricks where necessary to create everything dynamically and make it nice.
Update 2022-01-17: Finally fixed the bug that broke the patch when dragging near the bottom left corner. Everything should work now!