Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

-Cliptext with mouse button or paste text with mouse button.

Status
Not open for further replies.

jobsilva

Technical User
Jul 5, 2014
15
MX

Greetings!!!

I need copy some short text to the clipboard adding the Enter key and be able paste the text into any other Windows application like Word o Excel just with one click with the normal or left mouse button.
I already have the text in TextBox of Form.
I'm develop with Visual FoxPro ver. 9 with SP2.

It's possible?

Thanks and best Regards.
 
Copying the text to the clipboard is easy. In fact, judging by the title of the thread, I think you already know how do to that:

Code:
_CLIPTEXT = ALLTRIM(Thisform.Text1.Value) + CHR(13)

Do you also want to do the pasting programmatically? If so, there is no generic way of doing that, given that every application will be different. But in many cases, you could perhaps use SendKeys(). To take a simple example of pasting into Notepad:

Code:
oWSH = CREATEOBJECT("wscript.shell")
oWSH.Run("Notepad")
oWSH.SendKeys("^V")  && Send Ctlr+V to Notepad

You might also need to introduce a delay of a few hundred milliseconds after the oWSH.Run() to allow Notepad time to instantiate.

Pasting into Word or Excel would be more complicated because you would need to open the document first. But the general idea would be the same.

Keep in mind too the Word and Excel can be directly controlled via Automation. In other words, instead of going via the clipboard, you could insert the text directly into the document from VFP.

Mike





__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks a lot Mike, but it doesn't work for me.

Sorry for the duplicate post.
What they are asking me is to capture the school registration number obtained through fingerprint identification and put that number on the clipboard.
They will click on a text field of an X application from their library and they will have to paste that number together with the Enter.
So it is not a specific application.
They already had another application that did something similar and showed them how text could be passed to Word and Excel with just a normal click.
So far I have no problem moving to the clipboard.

_cliptext = n + CHR(13)
Keyboard '{CTRL+V}'

But I have to press Ctrl + V is another application.
And I need it to be with just one click

Regards
 
Just to make sure I've understood this ....

You are saying that the pasting won't be to any particular application. They might want to paste into Word, or Excel, or any one of a number of applications.

If that's right, I don't see how it can be done - for the reason I explained earlier. Even if you could be sure that the target application was already running, with the correct document open, and with the insertion point at the correct place, VFP would have no way of knowing which application you want to paste into.

The Windows Scripting Host can activate a specified application, and then sent CTRL+V to it. You can also do the same with Windows API calls. But, either way, you would still need to know the name of the target application (or the caption of its window).

You say they have another application that has this ability. It would be interesting to know if that is a VFP application, and exactly how it works.

It might be possible to achieve the goal via Automation, with your VFP app as the client, and Word or Excel or whatever as the server. But your code would still need to know which target app you were wanting to paste into.

Sorry I can't be more help. Maybe someone else here can come up with a solution.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
It's sad to know that.

I don't remember the name of your application, I also don't know what it was developed for, it was created by your students to keep track of book loans and it works in a network.
But what I could see was that, just by clicking, the license plate was copied to other places, including the browser.

So I thought that the content of the clipboard + Enter could be sent to the left mouse button in a general way using some Windows API to leave the content there for a few moments.

They don't want to type Ctrl + V + Enter.

They want it to be automatic.
 
Thank you very much Mike;

You have given me many clues.
I really appreciate your kindness, I admire and respect your knowledge very much.
I think I have already found the solution.
I found this software:

And it allows me to paste the contents of the clipboard and direct it to the left mouse button.
If I wanted to do the same with Visual FoxPro, I would need to learn more about the Windows API and the mouse.
I am very grateful for your trouble and kindness.

Best Regards.
 
Mouse clicks are Windows OS events. They are sent to the corresponding application, according to the coordinate of the mouse at the time it is clicked.

Mike has shown you can programmatically Send keys, but what you can't do is react to clicks that are not events of your application. That would require a general mouse hook and that may be done with some automation software, but it's not doable just with VFP and Windows API knowledge alone. At least not that I know how to.

It's not a good idea to override the left mouse click with whatever it causes naturally plus pasting what's in the clipboard. Not only because the clipboard does not get cleared and all your clicks do more than just the click action. It's a bad user interface choice, even if they are already used to that working in other cases. It goes against a lot of common UI rules to mix things up this way, that such demands are always an indicator to me of a customer not worth caring for, but that's just my personal opinion.

Baseline is, that's not how Windows works, for sure. I believe someone could come up with such a feature, if you dig deep into hooking into the system to atch all mouse clicks to any application, but that's truly a hack. Even if it's a hack for good, it's not what I'd support.

I look at this from another perspective: You have to do with someone why has a shortsighted way of optimising things. He's seeing a great advantage of saving a click by only needing the one left click instead of right click and picking paste from the context menu. The usual way to have high performance and automate data transfers is done by automation of applications that een remove the human to need to do much clicking at all. For me it doesn't pay to work with such small minded persons not able to think in a greater picture about strategies to optimize the workload for their employees. It's never done by saving a single click in a process, it's actually most often scuh jobs could be completely removed by automation.

Chriss
 
Jobsilva, regarding the X-Mouse Button Control that you linked to ....

This looks like a powerful piece of software, and a potentially useful one. But as far as I can see on a quick glance at the documentation, it won't solve your problem. Although it can simulate keystrokes (including CTRL+V) and can also directly instigate a copy/paste operation, it would still have to know what the target application us. So it would have exactly the same drawback as if you did it yourself in VFP.

I also agree with the very important point the Chris made about making the user interface behave in a non-standard way.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you, Mike and Chris;

They really are right and I have no excuses.

The programmer is here to help make things easier and safer.

And definitely what they ask me is not correct because it puts the functionality of Windows itself at risk.

There is no doubt that a lesson is learned every day and I greatly appreciate your wise advice.

I will try to explain to the client the risks of carrying out the change of the functionality of the mouse button as you kindly explained to me and the complexity of the work for them to assess and decide.

It only remains for me to thank you again for your wise advice and share your enormous knowledge.

I send you an affectionate hug.

Job Silva R.
 
One more thing that I remembered now is that there are complex mouses with additional buttons that also have drivers allowing to customize actions. Such as this one:
A screenshot of the mouse manager in it suggests that it's not unusual to put the past hotkey combinations CONTROl+C and CONTROL+V on mouse buttons. But I would still refrain from doing that on the normal left mouse button.

mouse_manager_profiles_seaxva.png


It may also be how they did what they have with a specific mouse and mouse driver allowing such settings.

Chriss
 
Take a look at the free Autohotkey.exe program.
In Autohotkey you can reprogram all keys, hotkeys and even mouse buttons in an AHK file.

Like:
MButton::Send ^v
or
~RButton::Send ^v (not recommended, just for testing)

This alters the Middle Button click or Right Button click into Control+V for pasting the clipboard. The ~ prefix allows to keep the original function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top