Is it possible to invoke a function when right clicking with a certain item?

I'm looking to use the knowledge book as an obtainable item used in a recipe, so I'm hoping to remove it disappearing on right click. I'm wondering if it's possible to invoke a function on right clicking while holding the knowledge book, where the function will give the player a new knowledge book (or if there's another way to disable the disappearing behaviour using a datapacks). Thanks!
Continue to help post