How can I paste data to other windows (who ever is accepting) ? [modified]
-
When I click a hot key combination (Ctrl+Shift+P) my program do copy some text to the clibboard, So I can paste it to any window by holding Ctrl+V Now I like to automate this and be able to do the Ctrl+V programatically, Lets assume I just want to paste just anything to other windows - so I can get started, I have tried this, but I guess I'm missing something: SendMessage(WM_PASTE, 0,0); also tried: BroadcastSystemMessage(BSF_POSTMESSAGE | BSF_IGNORECURRENTTASK, BSM_ALLCOMPONENTS, WM_PASTE, (WPARAM)NULL, (LPARAM)NULL); I'd like to broadcast a "paste" message (or "Ctrl+V") so I will not have to find the current active window and get its focus, Any suggestions ?
Best Regards - Yovav Gad CEO and founder of MicroMighty, Inc.
modified on Thursday, April 2, 2009 11:58 PM
-
When I click a hot key combination (Ctrl+Shift+P) my program do copy some text to the clibboard, So I can paste it to any window by holding Ctrl+V Now I like to automate this and be able to do the Ctrl+V programatically, Lets assume I just want to paste just anything to other windows - so I can get started, I have tried this, but I guess I'm missing something: SendMessage(WM_PASTE, 0,0); also tried: BroadcastSystemMessage(BSF_POSTMESSAGE | BSF_IGNORECURRENTTASK, BSM_ALLCOMPONENTS, WM_PASTE, (WPARAM)NULL, (LPARAM)NULL); I'd like to broadcast a "paste" message (or "Ctrl+V") so I will not have to find the current active window and get its focus, Any suggestions ?
Best Regards - Yovav Gad CEO and founder of MicroMighty, Inc.
modified on Thursday, April 2, 2009 11:58 PM
I tried something similar a few yeras back to aid in filling in forms that required the same data over and over, and as far as I can remember, different applications needed different handling. You have to try sending keystrokes to some, and WM_PASTE to some, and some applications do not even use a window, but a custom made input and cannot be manipulated at all. Sorry, but to my knowledge there is no universal method that works everywhere.
-
When I click a hot key combination (Ctrl+Shift+P) my program do copy some text to the clibboard, So I can paste it to any window by holding Ctrl+V Now I like to automate this and be able to do the Ctrl+V programatically, Lets assume I just want to paste just anything to other windows - so I can get started, I have tried this, but I guess I'm missing something: SendMessage(WM_PASTE, 0,0); also tried: BroadcastSystemMessage(BSF_POSTMESSAGE | BSF_IGNORECURRENTTASK, BSM_ALLCOMPONENTS, WM_PASTE, (WPARAM)NULL, (LPARAM)NULL); I'd like to broadcast a "paste" message (or "Ctrl+V") so I will not have to find the current active window and get its focus, Any suggestions ?
Best Regards - Yovav Gad CEO and founder of MicroMighty, Inc.
modified on Thursday, April 2, 2009 11:58 PM
In addition to Niklas' comments, I can see another problem. I'll pretend your idea works. You would then make EVERY top level window receive a paste message, so they'd all perform a paste. That includes explorer, Invisible windows controlling tray notification icons... And that may be a BAD THING(tm). Is it really so bad to have the user in control of their own PC? They spent the money on it, after all... Iain.
In the process of moving to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
-
I tried something similar a few yeras back to aid in filling in forms that required the same data over and over, and as far as I can remember, different applications needed different handling. You have to try sending keystrokes to some, and WM_PASTE to some, and some applications do not even use a window, but a custom made input and cannot be manipulated at all. Sorry, but to my knowledge there is no universal method that works everywhere.
Yea, you are probably right, I made some progress, however - it only works in some places (like notepad...) POINT pt; GetCursorPos(&pt); CWnd* editControl; editControl = WindowFromPoint(pt); editControl->GetFocus(); editControl->SendMessage(WM_PASTE, 0, 0); I also tried to programatically click Ctrl+V and cause a paste like this: ::SendMessage(GetForegroundWindow()->m_hWnd, WM_CHAR, 22, 0x56); But it seems to have the same problem - only works in some places (like notepad...) I wonder how can I better send the Ctrl+V and make the window/control think he got Ctrl+V clicked and do the paste for me (to which ever CEdit / CView control being used) Please let me know if you have any suggestions.
Best Regards - Yovav Gad CEO and founder of MicroMighty, Inc.
-
In addition to Niklas' comments, I can see another problem. I'll pretend your idea works. You would then make EVERY top level window receive a paste message, so they'd all perform a paste. That includes explorer, Invisible windows controlling tray notification icons... And that may be a BAD THING(tm). Is it really so bad to have the user in control of their own PC? They spent the money on it, after all... Iain.
In the process of moving to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
Well, its not really a problem - because I am sending the "WM_PASTE" message only to that specific control on which the user had put the cursor on, POINT pt; GetCursorPos(&pt); editControl = WindowFromPoint(pt); editControl->GetFocus(); editControl->SendMessage(WM_PASTE, 0, 0); Also - the user is not going to lose control over anything, This program gonna help users run and paste data exactly like they want it.
Best Regards - Yovav Gad CEO and founder of MicroMighty, Inc.
-
In addition to Niklas' comments, I can see another problem. I'll pretend your idea works. You would then make EVERY top level window receive a paste message, so they'd all perform a paste. That includes explorer, Invisible windows controlling tray notification icons... And that may be a BAD THING(tm). Is it really so bad to have the user in control of their own PC? They spent the money on it, after all... Iain.
In the process of moving to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
Iain Clarke wrote:
Is it really so bad to have the user in control of their own PC?
Well, yes and no :-D . In my specific case my friend got so tired of filling identical data (like company name and address) in some text fields over and over so I offerd a way to just put the cursor in the right place and hit a user defined short-cut-keystroke, et voila: User defined text -> clipboard -> edit control. I'm just saying there could be a good reason for doing this.
-
Iain Clarke wrote:
Is it really so bad to have the user in control of their own PC?
Well, yes and no :-D . In my specific case my friend got so tired of filling identical data (like company name and address) in some text fields over and over so I offerd a way to just put the cursor in the right place and hit a user defined short-cut-keystroke, et voila: User defined text -> clipboard -> edit control. I'm just saying there could be a good reason for doing this.
Well, my comment was more about the broadcast idea... I'll trust your domain expertise on this though. Or you mercenary desire for a customer to give you money! Iain.
In the process of moving to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
-
Yea, you are probably right, I made some progress, however - it only works in some places (like notepad...) POINT pt; GetCursorPos(&pt); CWnd* editControl; editControl = WindowFromPoint(pt); editControl->GetFocus(); editControl->SendMessage(WM_PASTE, 0, 0); I also tried to programatically click Ctrl+V and cause a paste like this: ::SendMessage(GetForegroundWindow()->m_hWnd, WM_CHAR, 22, 0x56); But it seems to have the same problem - only works in some places (like notepad...) I wonder how can I better send the Ctrl+V and make the window/control think he got Ctrl+V clicked and do the paste for me (to which ever CEdit / CView control being used) Please let me know if you have any suggestions.
Best Regards - Yovav Gad CEO and founder of MicroMighty, Inc.
Yovav wrote:
I wonder how can I better send the Ctrl+V...
Have you tried
keybd_event()
?"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
Iain Clarke wrote:
Is it really so bad to have the user in control of their own PC?
Well, yes and no :-D . In my specific case my friend got so tired of filling identical data (like company name and address) in some text fields over and over so I offerd a way to just put the cursor in the right place and hit a user defined short-cut-keystroke, et voila: User defined text -> clipboard -> edit control. I'm just saying there could be a good reason for doing this.
Niklas Lindquist wrote:
I'm just saying there could be a good reason for doing this.
And calling
BroadcastSystemMessage()
is not a solution for that reason."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
Niklas Lindquist wrote:
I'm just saying there could be a good reason for doing this.
And calling
BroadcastSystemMessage()
is not a solution for that reason."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
I don't understand exactly how the WM_PASTE message is getting picked up, but it might be safe to broardcast it everywhere if it only getting picked up in one place where the cursor and focus is, remember - my intention is to let the user who already have his cursor focused on some text control to paste specific data, but the user must put the focus first before it will do anything...
Best Regards - Yovav Gad CEO and founder of MicroMighty, Inc.