How would I speed up sprite movement over time?

Is there a way to move a sprite faster depending on how long a key is pressed?

if (key.isDown) {
    setVelocity(velocity++);
}

You could also use duration.

Thank you very much, @Milton!