从 PostMessage api 接收目标 window 中的陌生人字符串

Receiving strangers strings in target window from PostMessage api

我有一个远程管理工具,但在使用 PostMessage api 接收任何 window 中的字符串时遇到了麻烦。字符串通过服务器应用程序中的 TextBox 组件发送。

例如,单词 Coder 在 Whosebug window 中保持这样:

我使用的代码是这样的:

服务器应用程序

       private void tEnviarTexto_Click(object sender, EventArgs e)
        {

            String message = String.Format("<|MSG|>{0}", tEnviarMSG.Text);
            ListViewItem item = listView_clients.FocusedItem;
            String clientId = item.Name;
            RemoteClient client = this.remoteClientManager.GetClientById(clientId);
            if (client != null)
            {
                try
                {
                    client.mreMessage.WaitOne();
                    client.queueMessage.AddMessage(message);
                    tEnviarMSG.Text = "";
                }

                catch (Exception ex) { MessageBox.Show(ex.ToString()); }
            }
        }

客户端应用程序

       public void EnviatextoHWND(string texto)
        {
            foreach (char caractere in texto)
            {
                int charValue = caractere;
                string hexValue = charValue.ToString("X");
                IntPtr val = new IntPtr((Int32)caractere);

                string valor = val.ToString();

                if (valor == "66") // Letra B no Operador
                {
                    PostMessage(WindowHandle, WM_KEYDOWN, new IntPtr(VK_BACK), new IntPtr(0));
                    PostMessage(WindowHandle, WM_KEYUP, new IntPtr(VK_BACK), new IntPtr(0));

                }
                else if (valor == "83") // Letra S no Operador
                {
                    PostMessage(WindowHandle, WM_KEYDOWN, new IntPtr(VK_SPACE), new IntPtr(0));
                    PostMessage(WindowHandle, WM_KEYUP, new IntPtr(VK_SPACE), new IntPtr(0));

                }
                else
                {

                    PostMessage(WindowHandle, WM_KEYDOWN, val, new IntPtr(0));
                    PostMessage(WindowHandle, WM_CHAR, val, new IntPtr(0));
                    PostMessage(WindowHandle, WM_KEYUP, val, new IntPtr(0));

                } 
            }
        }

和用法:

public void CommunicationProc()
    {

      while (this.Connected)
        {
         else if (message.IndexOf("<|MSG|>") == 0)
          {
            String[] strSplit = value.Split(MenuRemoteClient.separator, StringSplitOptions.None);
            string msg = strSplit[0]; // content from a TextBox on Server application

                   if (this.remotedNav)
                     {
                       Thread SendTextoHWND = new Thread(() => EnviatextoHWND(msg));
                           SendTextoHWND.Start();
                            }
                        }
                }
             }

那么,怎么解决呢?

如有任何建议或指导,我们将不胜感激。

固定:

             //   PostMessage(WindowHandle, WM_KEYDOWN, val, new IntPtr(0));
                PostMessage(WindowHandle, WM_CHAR, val, new IntPtr(0));
            //    PostMessage(WindowHandle, WM_KEYUP, val, new IntPtr(0));