XiAce-Lite / SyncRoomChatToolV2

SyncRoomV2のチャットを読み上げたり、書き込んだりします。
0 stars 0 forks source link

Hello, I have a question. #1

Open HaebinAHN opened 3 months ago

HaebinAHN commented 3 months ago

Hello. I am a Syncroom user playing in Korea. I have a question to you... can you reply to gnh06280@naver.com ?

How did you get the messages from Syncroom client?

HaebinAHN commented 3 months ago

日本語で答えてもいい。

XiAce-Lite commented 3 months ago

You can get UI Automation element named "chatList" from SyncRoom2.exe(using inspect.exe that included Visual Studio)

See the line 839 to 842 in "MainWindow.xaml.cs".

See source for detail.

HaebinAHN commented 3 months ago

Thank you for your replying. I want to make a Syncroom chatting program with another window. But I have a problem with getting 'studio'. I followed your code, but studio is always null. So I tried to get a message while running program. I checked the inspect.exe but there are a lot of blanks at tree nodes and I can't get nodes' name exactly. I could see chatList but below the SYNCROOM 2, I can't get any nodes there with my code. My C# version is 7.3

I'll so glad if you reply again. Thank you.

private async Task MonitorChat()
        {
            string targetProcessName = "SYNCROOM2";
            string oldMessage = "";
            bool firstFlg = true;

            while (running)
            {
                try
                {
                    var processes = Process.GetProcessesByName(targetProcessName);
                    AutomationElement rootElement = null;

                    if (processes.Length == 0)
                    {
                        await UpdateUI("싱크룸2가 인식되지 않았습니다", "5초 후 다시 감지합니다..");
                        await Task.Delay(5000);
                        continue;
                    }

                    var chatProcess = processes[0];
                    rootElement = AutomationElement.FromHandle(chatProcess.MainWindowHandle);
                    // TreeWalker를 사용하여 자식 요소들을 탐색합니다.
                    TreeWalker walker = TreeWalker.ControlViewWalker;
                    AutomationElement currentElement = walker.GetFirstChild(rootElement);
                    if (rootElement == null)
                    {
                        await UpdateUI("오류", "Root element를 찾을 수 없습니다.");
                        continue;
                    }
                    while (currentElement != null)
                    {
                        // 각 요소의 속성을 출력합니다.
                        await UpdateUI("Name: " + currentElement.Current.Name, "");
                        await UpdateUI("AutomationId: " + currentElement.Current.AutomationId, "");
                        await UpdateUI("ControlType: " + currentElement.Current.ControlType.ProgrammaticName, "");
                        await UpdateUI("ClassName: " + currentElement.Current.ClassName, "");
                        await UpdateUI("-----------------------------", "");

                        // 다음 형제 요소로 이동합니다.
                        currentElement = walker.GetNextSibling(currentElement);
                    }
                    break;

                    ...
    private async Task UpdateUI(string userName, string chatContent)
        {
            if (InvokeRequired)
            {
                await Task.Run(() => Invoke(new Action<string, string>(async (u, c) => await UpdateUI(u, c)), new object[] { userName, chatContent }));
            }
            else
            {
                //TextBox2.Text += (userName + ": " + chatContent + "\n");
                TextBox2.Text += (userName + "");
            }
        }
XiAce-Lite commented 3 months ago

You and I got RootElement FromHandle. Maybe It's OK.

But you wrote,

TreeWalker walker = TreeWalker.ControlViewWalker; AutomationElement currentElement = walker.GetFirstChild(rootElement);

this means "Get First Child Control under RootElement". But "studio" element is not FIRST control.

See the line 667 in MainWindow.xaml.cs. You shoud better get "studio" element by AutomationId.

And, "studio" element genarated after entering room. before you enter room, it's not genarated by Syncroom process.

I guest, the fastest way to know how to get syncroom chats,

If differences between KR ver and JP ver, I can't help your problem. I got "studio" element using by inspect.exe, it's the first step to analysis syncroom2 process.

Run Syncroom2.exe and enter private room, then you watch the element trees in detail using by inspect.exe.