Writing Code to Simultaneously Move Cursor and Dot, Restricting Mouse Movement to Y-Axis"

What I want to do is: Imagine a dot on the screen with the cursor in the middle of the screen. I move the cursor upward only, and the dot extends into a line following the cursor. When I click, I save the response.


How do I write a code that will move the cursor and the dot simultaneously and by restricting the mouse movement only in y axis:**

So far with these I can see the dot and cursor in the middle of the screen but couldn’t restrict the mouse movement: