type() foreign symbol example

Asked by Muro

Happy New Year to everybody!
Looking for example how to type() foreign symbol for example german 'umlaute' or any other.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
j (j-the-k) said :
#1

This is a major problem in Sikuli.
The only way I found working is using the OS-support for special chars, like holding the ALT-key and typing on numblock on windows (see http://symbolcodes.tlt.psu.edu/accents/codealt.html for more details).
As far as I experienced Sikuli, the typing works only right on a default English keyboard layout.
The problem is that Sikuli uses the Java AWT Robot which I found not really compatible with other keyboard layouts than English.

Revision history for this message
RaiMan (raimund-hocke) said :
#2

@ j-the-k
thanks for this link. one of the best sites about keyboards, foreign codes and unicode.
I have added it to the faq 933

Revision history for this message
Muro (muromail) said :
#3

@ j-the-k
thank you.

@ RaiMan
Can you give us example of your use here:

--- This is read into a key-value storage using clipboard (by eval()) and analyzed.
--- " \ and the diacritic characters (´`^~¨) need special handling
--- The result is a key-value storage, containing for all 256 extended ASCII characters the equivalents that have to be used with type(), to get the character you want.
--- So I am able to fully utilize my german keyboard and type() every text, that can be produced with this keyboard (since I use JRuby, it is easy to redefine the Region.type() method (actually it is the type_ch() method, that contains the translation), to use this "german" translation table)
--- I am using YAML to store and reload the tables

i`m newbie in python i`ll try with dictionary but it return all array:

def type_ger(line):
    for letter in line:
     type_german(letter)

def type_german(letter):
    return {

            'ü': type('['),
     'ö': type(';'),
         }[letter]
click(Pattern("pic.png").targetOffset(-151,53))
type_ger('ü')

it works
but it return all symbol from array and break with error:

[error] Stopped
[error] An error occurs at line 14
[error] Error message: Traceback (most recent call last):
 File "C:\Users\User\AppData\Local\Temp\sikuli-tmp2204018246795003748.py", line 14, in
 type_ger('ü')
File "C:\Users\User\AppData\Local\Temp\sikuli-tmp2204018246795003748.py", line 3, in type_ger
 type_german(letter)
 File "C:\Users\User\AppData\Local\Temp\sikuli-tmp2204018246795003748.py", line 6, in type_german
 return {
KeyError: Ã

Revision history for this message
RaiMan (raimund-hocke) said :
#4

you do not need a def() "type_german" for that, the dictionary is sufficient:

e.g.

german = {u"ü":'[', u"ö":';'}

def type_ger(line):
    for letter in line:
     type(german.get(letter, letter)) # if the letter is not in the dict, the letter itself is typed
     # so the dict only needs to contain letters that has to be translated.

type_ger(u"Flöte")

tested on Mac with a textedit window

Revision history for this message
Muro (muromail) said :
#5

@RaiMan

Thank you for this!

german = {u"ü":'[', u"ö":';'}

def type_ger(line):
    for letter in line:
     type(german.get(letter, letter)) # if the letter is not in the dict, the letter itself is typed
     # so the dict only needs to contain letters that has to be translated.

type_ger(u"Flöte")

but it return ...

Fl;te

tested on Windows 7 x86 Ultimate with Notepad

Revision history for this message
RaiMan (raimund-hocke) said :
#6

Is really Fl;te typed in Notepad or is this just shown in the message area of IDE?

I cannot test it on Windows, since I do not have any pure Windows on a PC.

If you are running with a US/EN layout, than this will not work. The keyboard (even if it is US, it must be run as German).

If this does not work, you have to use paste() for the text part of your type()'s

Revision history for this message
Muro (muromail) said :
#7

Yes i`m running with US\EN layout.I`m working with element that need type() method...
Are there any other solution? What about your solution?

--- This is read into a key-value storage using clipboard (by eval()) and analyzed.
--- " \ and the diacritic characters (´`^~¨) need special handling
--- The result is a key-value storage, containing for all 256 extended ASCII characters the equivalents that have to be used with type(), to get the character you want.
--- So I am able to fully utilize my german keyboard and type() every text, that can be produced with this keyboard (since I use JRuby, it is easy to redefine the Region.type() method (actually it is the type_ch() method, that contains the translation), to use this "german" translation table)
--- I am using YAML to store and reload the tables

Can you short example ?

Revision history for this message
Best RaiMan (raimund-hocke) said :
#8

This is principally, what you have tried.
But it only works, if you have a foreign (not en-us) layout active while running the script, to produce the characters you see on your keyboard using type().
So i can produce an ö via type(), by typing a [
The mentioned solution is a procedure to "learn" the foreign keyboard and to produce the translation table.

What you are looking for is a solution, to produce characters that are NOT on your keyboard.

And there I come back to j-th-k's suggestion based on the alt-nnn solution.
so e.g ö is alt-0246

the solution:
german = { u"ä", "0228", u"ö", "0246", u"ü", "0252"  }

def type_ger(line):
    for letter in line:
        nums = german.get(letter, ""))
        if nums == "":
            type(letter)
            return
        keyDown(Key.ALT)
        for n in nums:
            eval( "type(Key.NUM" + n + ")" )
        keyUp()

type_ger(u"Flöte")

Revision history for this message
Muro (muromail) said :
#9

Thanks RaiMan, that solved my question.

Revision history for this message
Muro (muromail) said :
#10

Tips: In windows you can run charmap.exe and find any symbol ALT + key code number.

Revision history for this message
necips (necips) said :
#11

So funktioniert es auf meinem Rechner!

german = {u"ä":"0228", u"ö":"0246", u"ü":"0252"}

def type_ger(line):
    for letter in line:
        nums = german.get(letter, "")
        if nums == "":
            type(letter)
        else :
            keyDown(Key.ALT)
            for n in nums:
                eval( "type(Key.NUM" + n + ")")
            keyUp()

type_ger(u"Flöte")