예제 #1
0
        static void Main(string[] args)
        {
//            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");
            RimeTraits traits = new RimeTraits();

            traits.app_name = "YIME.PlayGround";

            Rime.RimeSetup(ref traits);
            Console.WriteLine("初始化1");
            Rime.RimeInitialize(IntPtr.Zero);
            Console.WriteLine("初始化2");
            Rime.RimeSetNotificationHandler(Handler, IntPtr.Zero);
            if (Rime.RimeStartMaintenance(true))
            {
                Rime.RimeJoinMaintenanceThread();
            }


            var rimesessionid = Rime.RimeCreateSession();

            Console.WriteLine("Session ID: " + rimesessionid);


            while (true)
            {
                var key = Console.ReadKey();
                if (key.Key == ConsoleKey.Escape)
                {
                    break;
                }
                Console.WriteLine();
                Rime.RimeSimulateKeySequence(rimesessionid, key.KeyChar.ToString());

                var commit  = new RimeCommit();
                var status  = new RimeStatus();
                var context = new RimeContext();
                commit.Init();
                status.Init();
                context.Init();

                Rime.RimeGetCommit(rimesessionid, ref commit);
                Rime.RimeGetStatus(rimesessionid, ref status);
                Rime.RimeGetContext(rimesessionid, ref context);
                Console.WriteLine("Commit:" + commit.text);
                Console.WriteLine($"Status: {status.is_composing},{status.is_ascii_mode}, {status.schema_name}");
                Console.WriteLine($"Context: {context.commit_text_preview}, {context.composition.preedit}");
                var candiates =
                    RimeApi.Common.StuctArrayFromIntPtr <RimeCandidate>(context.menu.candidates,
                                                                        context.menu.num_candidates);
                for (int i = 0; i < context.menu.num_candidates; i++)
                {
                    Console.WriteLine($"{i+1}: {candiates[i].text}");
                }
            }
        }
예제 #2
0
        private void OnKeyDown(object sender, KeyEventArgs keyEventArgs)
        {
            string press = "";

            switch (keyEventArgs.Key)
            {
            case Key.OemPlus:
                press = "=";
                break;

            case Key.OemMinus:
                press = "-";
                break;

            case Key.Space:
                press = " ";
                break;

            default:
                press = converter.ConvertToString(keyEventArgs.Key).ToLower();
                break;
            }

            if (press.Length == 1)
            {
                char pressedkey = press.ToCharArray()[0];
                if (pressedkey >= 'a' && pressedkey <= 'z')
                {
                    Rime.RimeProcessKey(rimesessionid, (int)pressedkey, 0);
                    var tmp = update();
                    updatebaidu(tmp);
                }
                else if (pressedkey == '-' || pressedkey == '=')
                {
                    Rime.RimeProcessKey(rimesessionid, (int)pressedkey, 0);
                    update();
                }
                else if ((pressedkey >= '1' && pressedkey <= '5') || pressedkey == ' ')
                {
                    Rime.RimeProcessKey(rimesessionid, (int)pressedkey, 0);
                    update();
                }
                else if (pressedkey == '6')
                {
                    if (!string.IsNullOrEmpty(baiduresult))
                    {
                        this.tb.Text    = "";
                        this.lb.Content = baiduresult;
                        Rime.RimeClearComposition(rimesessionid);
                    }
                }
            }
        }
예제 #3
0
        /* Get la rime depuis la console, contrôle le format */
        private Rime getRime()
        {
            Regex myRegex = new Regex("/./");

            Console.WriteLine("Indiquez la rime sous le format /a/");
            string rime = Console.ReadLine();

            bool boolResult = myRegex.IsMatch(rime);

            while (boolResult == false)
            {
                Console.WriteLine("format non reconnus");
                Console.WriteLine("Indiquez la rime sous le format /a/");
                rime       = Console.ReadLine();
                boolResult = myRegex.IsMatch(rime);
            }

            Rime rimeObject = new Rime(rime);

            return(rimeObject);
        }
예제 #4
0
        string update()
        {
            var commit  = new RimeCommit();
            var status  = new RimeStatus();
            var context = new RimeContext();

            commit.Init();
            status.Init();
            context.Init();

            Rime.RimeGetCommit(rimesessionid, ref commit);
            Rime.RimeGetStatus(rimesessionid, ref status);
            Rime.RimeGetContext(rimesessionid, ref context);
            if (!string.IsNullOrEmpty(commit.text))
            {
                this.tb.Text    = "";
                this.lb.Content = commit.text;
            }
            if (status.is_composing)
            {
                this.lb.Content = context.composition.preedit;
                var candiates =
                    RimeApi.Common.StuctArrayFromIntPtr <RimeCandidate>(context.menu.candidates,
                                                                        context.menu.num_candidates);
                sblist.Clear();

                for (int i = 0; i < context.menu.num_candidates; i++)
                {
                    sblist.Add(candiates[i].text);
                }
                updatelistdisplay();
            }
            else
            {
                this.tb.Text = "";
            }

            return(context.composition.preedit);
        }
예제 #5
0
        public MainWindow()
        {
            InitializeComponent();
            converter = new KeyConverter();
            RimeTraits traits = new RimeTraits();

            traits.app_name = "YIME.PlayGround";

            Rime.RimeSetup(ref traits);
            Console.WriteLine("初始化1");
            Rime.RimeInitialize(IntPtr.Zero);
            Console.WriteLine("初始化2");
            if (Rime.RimeStartMaintenance(true))
            {
                Rime.RimeJoinMaintenanceThread();
            }


            rimesessionid = Rime.RimeCreateSession();
            Console.WriteLine("Session ID: " + rimesessionid);
            this.KeyDown += OnKeyDown;
        }
예제 #6
0
 public override void InitData()
 {
     exporter = new Rime();
     importer = new Rime();
 }
예제 #7
0
 public Vers(string b)
 {
     rime    = getRime();
     content = b;
     Console.WriteLine("Vers crée");
 }