If you're able to use linear algebra, then you'll want to detect the distance from your test point, to the nearest point on your line segment.
- Let AB be your line Segment.
- Let C be your mouse point.
- Let D be a point on AB such that the line segment CD is minimal.
You want to find the length of CD. Since AB and CD are perpendicular, you know that the slope of AB is the inverse reciprocal of the slope of CD. You know C, and a slope, so you can find the general equation for CD. Then, find the intersection of AB and CD, giving you point D.
Once you have point D, finding the length of CD is trivial. If this distance is less than some threshold value, then you know you've clicked near the line segment you're interested in.