← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #156443]: Jython: how to paste chinese characters (unicode characters)

 

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

Description changed to:
This solution only applies to scripts run by using a Jython interpreter
directly or other Java based scripting solutions like JRuby.

For Jython you need 2 things:
--1. Python encoding directive
in the first or second line of your script you need a magic comment that defines the encoding used for the script:
# coding=utf-8
Of course: your script has to be stored as file with utf-8 encoding by your script editor.
--2. you have to tell the JVM, the same thing by giving this as a parameter when calling the JVM:
-Dfile.encoding=utf-8

Below in comments #4 and #5 find a description of a successful test with
plain Jython by coldtest(https://launchpad.net/~tesger)

This is not needed with scripts run with the support of Sikuli IDE or run with one of the approaches from http://sikuli.org/docx/faq/010-command-line.html.
---------------------------------------------------------------------------------------------------------------------------------------------------------------- 


 I used the paste function to input the chinese to notepad in jruby script ,but it can't be correct in the notepad. they are  distorted Character Code , the script as follow:
require 'rubygems'
require 'java'
require 'iconv'

java_import "org.sikuli.script.SikuliScript"
java_import "org.sikuli.script.Region"
java_import "org.sikuli.script.Screen"
java_import "org.sikuli.script.App"


screen=Screen.new
App.focus("notepad")
sleep(1)
str = "梅西"
sleep(2);
screen.paste("1.png",str)


but it is correct when I use paste function in sikuli IDE ,the script as fellow:

App.focus("notepad")
sleep(3)
paste( ,"梅西")

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