Automatic keyboard detection

[endlessm/eos-shell#3425]
I recommend moving this whole big `if` block into a separate function that takes the line as an input.
That way you could remove the duplicated `g_free(line)` from all the branches and refactor the code to be something like
```
while ((line = readline()))
  {
    process_line(line);
    g_free(line);
  }
```