Automatic keyboard detection

[endlessm/eos-shell#3425]
It was a bit more complicated than that, so I put the refactor in a separate commit.