I have a vim script that uses a one line window to get a filename pattern from the user. This pattern can be completed to a full filename from a database if you press CTRL-X
You should look at :h autocmd. I believe the InsertChange event could be used to do what you want.
:h autocmd
InsertChange