How to detect offhand swap and put original offhand item back in player offhand

Pretty simple, I want to detect when the player uses the f key to swap the item they're holding into their offhand and then run a function. I also want it to put the original item that was in their offhand back in their mainhand.

Continue to help post