Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

SendInput to copy/paste doesn't work in a new thread

$
0
0

Hi everyone,

I'm actually working on an application sending keystrokes input to any application choosed by the user. On a specific input from the user, sendinput is called to send copy keystrokes to the focused window. The listening and action on event are located in a infinite loop for waiting the user input. All is working fine, i can got the result without any problem with 

System.Windows.Forms.Clipboard.GetText()

 I put this piece of code in a new thread to listen in the background (goal is the create this thread from a WPF application),

Putting this code in a thread, nothing can be copied. The user input is catch and processed, the application follow the same code, but an empty string is returned by GetText methods.

I tried to send the same keystroke with InputSimulator, a C# library and keybd_event function but it's the same problem, working well with the loop in the main thread, but in a new thread, it doesn't copy anything.

I just have to swap the comments to change the behavior. listenProcess is a static method.

[STAThread]staticvoidMain(string[] args){// listenProcess();//*Thread ma =newThread(newThreadStart(listenProcess));Console.WriteLine("thread start");
            ma.Start();Console.WriteLine("thread join");
            ma.Join();Console.WriteLine("thread end");//*/}

Do you have any idea with the Copy keystroke doesn't work an a new thread ? Any idea or suggestion would be appreciated.

Working on VS 2012, target .NET 3.5

Thanks,

Marcassin


Viewing all articles
Browse latest Browse all 31927

Trending Articles