Sending data to a notepad using processes

后端 未结 5 1172
余生分开走
余生分开走 2021-01-23 21:11

I want to send every item from my listbox to a notepad,but my logic is kinda beating me.

private void send_Click(object sender, EventArgs e)
{
    var notepad =          


        
5条回答
  •  有刺的猬
    2021-01-23 21:55

    You can do it with InputSimulator, Package Manage Console: Install-Package InputSimulator

     private void Button_Click_1(object sender, RoutedEventArgs e)
                {
    
                    var notepad = Process.GetProcessesByName("Notepad").FirstOrDefault(p => p.MainWindowTitle == "Untitled - Notepad");
                    if (notepad != null)
                    {
                        if (IsIconic(notepad.MainWindowHandle))
                            ShowWindow(notepad.MainWindowHandle, 9);
    
                        var input = new InputSimulator();
                        SetForegroundWindow(notepad.MainWindowHandle);
                        foreach (var item in listBox1.Items)
                        {
                            input.Keyboard.TextEntry(item.ToString());
                            input.Keyboard.KeyPress(VirtualKeyCode.RETURN);
    
                        }
                    }
                }
    

提交回复
热议问题