Hotkey to make cursor in straight line

I am trying to do a simple script like maya ‘painting’. While the painting works, I am trying to integrate in a hotkey modifier such that if the user press and hold the Shift key, it will paint the object in a straight line, so i guess this is mainly for the mouse cursor position?

I tried to look up for such details online but to no avail results, perhaps I am searching it incorrectly.
Could anyone kindly tell me how to do it, or give me some examples?