Minecraft allows you to rebind the "Open/Close Inventory" key to a mouse button - however doing so will allow you to only open your inventory with that button, not close it.
This is a fix for that for Forge versions of Minecraft.
A Fabric version exists already here.
The Minecraft bug has existed for nearly ten years. The most recent tracker is MC-156810
Links
Featured versions
See allProject members
Iridium
Owner
Technical information
License
MIT
Client side
required
Server side
unsupported
Project ID