I'm trying to programmatically make an external WinForms application copy its data to the clipboard, and it's driving me crazy.
Since pressing Ctrl-C in the application does the right thing, I've been trying to send ctrl-c using my C# application to the other application.
Here is my sequence of commands. I compared the messages using Spy++, and it matches except for my SendMessages are showing up as Send and Receive, vs. the same operation done on the WinForm is showing up as posted.
My code :
NativeMethods.SendMessage(hwnd, WM_KEYDOWN, 0x00000011, 0x001D0001);
NativeMethods.SendMessage(hwnd, WM_KEYDOWN, 0x00000043, 0x002E0001);
NativeMethods.SendMessage(hwnd, WM_CHAR, 0x00000003, 0x002E0001);
NativeMethods.SendMessage(hwnd, WM_KEYUP, 0x00000043, 0xC02E0001);
NativeMethods.SendMessage(hwnd, WM_KEYUP, 0x00000011, 0xC01D0001);
Spy++ auto Run ->
0059043C P WM_LBUTTONDOWN fwKeys:MK_LBUTTON xPos:322 yPos:54 [wParam:00000001 lParam:00360142] 0059043C P WM_LBUTTONUP fwKeys:0000 xPos:322 yPos:54 [wParam:00000000 lParam:00360142] 0059043C P WM_KEYDOWN nVirtKey:VK_CONTROL cRepeat:1 ScanCode:1D fExtended:0 fAltDown:0 fRepeat:0 fUp:0 [wParam:00000011 lParam:001D0001] 0059043C P WM_KEYDOWN nVirtKey:'C' cRepeat:1 ScanCode:2E fExtended:0 fAltDown:0 fRepeat:0 fUp:0 [wParam:00000043 lParam:002E0001] 0059043C P WM_CHAR chCharCode:'3' (3) cRepeat:1 ScanCode:2E fExtended:0 fAltDown:0 fRepeat:0 fUp:0 [wParam:00000003 lParam:002E0001] 0059043C P WM_KEYUP nVirtKey:'C' cRepeat:1 ScanCode:2E fExtended:0 fAltDown:0 fRepeat:1 fUp:1 [wParam:00000043 lParam:C02E0001] 0059043C P WM_KEYUP nVirtKey:VK_CONTROL cRepeat:1 ScanCode:1D fExtended:0 fAltDown:0 fRepeat:1 fUp:1 [wParam:00000011 lParam:C01D0001]
My Spy++ sequence :
0059043C S WM_LBUTTONDOWN fwKeys:MK_LBUTTON xPos:299 yPos:52 [wParam:00000001 lParam:0034012B] 0059043C R WM_LBUTTONDOWN 0059043C S WM_LBUTTONUP fwKeys:MK_LBUTTON xPos:299 yPos:52 [wParam:00000001 lParam:0034012B] 0059043C R WM_LBUTTONUP 0059043C S WM_KEYDOWN nVirtKey:VK_CONTROL cRepeat:1 ScanCode:1D fExtended:0 fAltDown:0 fRepeat:0 fUp:0 [wParam:00000011 lParam:001D0001] 0059043C R WM_KEYDOWN 0059043C S WM_KEYDOWN nVirtKey:'C' cRepeat:1 ScanCode:2E fExtended:0 fAltDown:0 fRepeat:0 fUp:0 [wParam:00000043 lParam:002E0001] 0059043C R WM_KEYDOWN 0059043C S WM_CHAR chCharCode:'3' (3) cRepeat:1 ScanCode:2E fExtended:0 fAltDown:0 fRepeat:0 fUp:0 [wParam:00000003 lParam:002E0001] 0059043C R WM_CHAR 0059043C S WM_KEYUP nVirtKey:'C' cRepeat:1 ScanCode:2E fExtended:0 fAltDown:0 fRepeat:1 fUp:1 [wParam:00000043 lParam:C02E0001] 0059043C R WM_KEYUP 0059043C S WM_KEYUP nVirtKey:VK_CONTROL cRepeat:1 ScanCode:1D fExtended:0 fAltDown:0 fRepeat:1 fUp:1 [wParam:00000011 lParam:C01D0001] 0059043C R WM_KEYUP
You could use PostMessage
Or try SendInput, although then you have to give the target window the focus first.
User contributions licensed under CC BY-SA 3.0