Click here to Skip to main content
15,906,329 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,

I used this code to print data from another application to notepad automatically:

C#
IntPtr h = p.MainWindowHandle;
SetForegroundWindow(h);                                       
SendKeys.SendWait(Clipboard.GetText(TextDataFormat.Text));
Clipboard.Clear();


it works fine for the first attempt but it adds duplicate value for the next attempt.

What I have tried:

this is what i get from the sendkeys:

1 attempt
13.00
2nd atttempt
223.00 but it has to print 23.00
Posted
Updated 18-May-16 1:11am
v3
Comments
Richard MacCutchan 17-May-16 9:07am    
What is in the ClipBoard?
Member 11183856 17-May-16 9:13am    
in the clipboard at first attempt it will have 13.00 for second attempt it has 23.00
Member 11183856 17-May-16 9:14am    
i checked with ctrl+v command it hast the same value but on automatic printing it has duplicate value
Richard MacCutchan 17-May-16 10:13am    
You must be pasting it somewhere which already has some text.
Richard Deeming 17-May-16 13:14pm    
Try: SendKeys.SendWait("^a{DEL}^v")

That should select all text in the window (^a = Ctrl+a), delete it ({DEL} = Delete), and then paste the contents of the clipboard (^v = Ctrl+v).

1 solution

Try:
C#
IntPtr h = p.MainWindowHandle;
SetForegroundWindow(h);                                       
SendKeys.SendWait("^a{DEL}^v");
Clipboard.Clear();

That should select all text in the window (^a = Ctrl+a), delete it ({DEL} = Delete), and then paste the contents of the clipboard (^v = Ctrl+v).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900