I don't know how to write any of the code, but I do have an idea of how you can approach the problem:
Get the user input, if it matches the mouse button your looking for, go onto a while loop which is while the mouse button is held down, call a click function which, surprisingly, clicks. Some pseudo-code below.
int input = get_user_input();
if(input == MOUSE_BUTTON_LEFT)
while(get_user_input(MOUSE_BUTTON_LEFT) == BUTTON_PRESS)