Fred
Fred

Reputation: 1021

Convert keyboard azerty to qwerty and vice-versa

Is there a module for converting the letters of a AZERTY keyboard in a QWERTY keyboard letters and vice versa?

To do this it must also be able to detect the keyboard type, is it possible?

Example: 'data'. to_qwerty () -> 'dqtq' or 'dqtq'. to_azerty () -> 'data'

Or a simple solution without having to type all the letters of each letter?

Thank you in advance.

Upvotes: 2

Views: 3405

Answers (1)

Mattias Nilsson
Mattias Nilsson

Reputation: 3757

If you just want to convert one string to another, that's pretty simple: (it does however require you to specify how they translate from one to the other)

>>> translate_dict = dict(zip("abcdef", "123456"))
>>> translate_this = "deadbeef"
>>> ''.join([translate_dict.get(x) for x in translate_this])
'45142556'

or

>>> ''.join(map(translate_dict.get, translate_this))
'45142556'

... or any number of ways to do this in a few lines.

If you want to get fancy and do something similar to what you did in your question (call a method on a string and have it converted) then you can have a look at the codecs module that will let you do that. Takes a bit more work, but you would be able to do something like this

>>> mystring.encode('qwerty')

The big effort is probably getting the data on how to translate everything.

The easiest thing is probably to make sure you have the right keymap before starting to type. :)

Upvotes: 5

Related Questions