← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #201882]: Replace chars in a var - string is UTF-8 encoded

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
this works for me:

fullName =  Env.getClipboard().strip().encode("utf-8")
print fullName # prints correctly
paste(fullName) # pastes correctly

So after getting it from clipboard in the correct encoding, all
subsequent operations including paste() do not need any special
handling, since fullName is utf-8 and Sikuli in total (on the Python
level is utf-8 aware).

The only exception is the interface to the Java level (like with
Env.getClipboard() and popup(), that need conversions).

One more thing:
There is a bug, so that Env.getClipboard() does not work anymore, after having used paste() the first time in your script.
So your snippet only works once in a script anyway.

If you have the knowhow, you might try to solve it yourself on the Java
level using Java's clipboard functions directly

type("a",KEY_CTRL + KEY_SHIFT)
type("c",KEY_CTRL)
fulllName = myGetClipboard()
# some coding
mySetClipBoard(some_text)
# position cursor
type("v", KEY_CTRL)

where myGetClipboard/mySetClipBoard are your own functions using the
Java clipboard features.

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