Support key mappings of more than 2 keys

Fixes #1271.