← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #215388]: Issue with type()

 

Question #215388 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/215388

    Status: Open => Answered

RaiMan proposed the following answer:
The problem is your print statement:

 print "MyGeneral.Type - TextToType: "+str(TextToType)

Since when using:

MyGeneral.Type(Key.PAGE_DOWN)
(which must be used this way without "" for type() to work correctly)

TextToType contains a unicode character that is used internally to
translate Key.PAGE_DOWN to the final Java KeyCode.

This character cannot be printed with the normal print.

This print statement would work without error:

print ("MyGeneral.Type - TextToType: "+str(TextToType)).encode("utf8")

but the Key.XXX would be printed with the unicode characters (PAGE_DOWN
e.g. a little square), which might not be whatr you expect.

Sorry, but there is no simple solution for that.

The only simple solution for text and one key would be something like
that:

def Type(TextToType, theKey):
    print "MyGeneral.Type - TextToType: "+str(TextToType) +" "+theKey
    if TextToType != "":
        exec('type("' + TextToType '" + theKey +")")
    else:
        exec("type("+ theKey +")")

usage:
MyGeneral.Type("", Key.PAGE_DOWN) 

or

MyGeneral.Type("some text", Key.DOWN)

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.