Why does an item disappear from my inventory when I press Q?

I was fighting a zombie in a cave. I accidentally pressed Q and my diamond sword disappeared. When I switched to another diamond sword to test it also disappeared when I pressed Q.

Why is this happening, and what can I do to prevent it?


Solution 1:

The Q key is bound to Drop Item by default. The sword didn't 'disappear', it just fell on the floor. You can pick it back up by standing near the dropped item, but it will disappear if you don't pick it up within 5 minutes (6000 game ticks).