Make non-SDL code indipendent from SDL, fix keyboard issues