If you open a chest and click an item trying to pick it up, and it instantly moves to the other inventory: Tap left shift, left ctrl, left alt, right shift, right ctrl, right alt (or the mac equivalent, no idea) a few times until it fixes. I don't know what causes it, but that has always fixed it for me.
This is not unique to minecraft. A shifting key (ctrl, alt, shift, option, command, menu, windows) or a mouse button (right, center, 4, 5) is stuck. Press and release every single one. Then retry.