You are not the first to ask for this. Obviously, this is possible. The question is how much effort is involved.

Which scanner is it? I'm guessing that different scanners will require different techniques.

The buttons on my scanner are not exposed by the SANE backend, which will make any sort of development work in this direction tricky.