I hadn’t noticed the problem with several keys like | \ and ~ not correctly mapping from a USB connected keyboard because I usually interface with SSH. Today, I had a USB keyboard plugged into a Pi and was trying to pipe through grep and I kept getting a ~ instead of |. It turns out that the default keyboard on your Pi is set for Great Britain instead of US. Here’s the fix:

vi or nano into    /etc/default/keyboard

change from XKBLAYOUT="gb"  to  XKBLAYOUT="us" .

Tom / K5TRA