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!

How to key in enter key after paste? 3

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
578
PH
I have put an info to the clipboard, is it possible to paste the info from clipboard with enter key to the textbox if i click the paste button? Thanks

PROCEDURE CmdCopy.click()

_cliptext = this.Parent.text1.value

ENDPROC

PROCEDURE CmdPaste.click()

this.parent.text40.value = _cliptext + CHR(13)
CODE....
CODE....​

ENDPROC
 
Mandy,

The code that you posted looks like it will do the following:

- You have a Paste button and a textbox on a form.

- When the user clicks on the button, the contents of the clipboard will be pasted intto the textbox.

- And then focus will then move off the texbox to the next control (as if the user had pressed the Enter key).

Is that what you want? And if not, please explain more clearly what you are trying to achieve.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You should also be aware that the best way to deal with copying and pasting in a VFP app is to implement the standard shortcut keys (CTRL+C, CTRL+X, CTRL+V). And the easiest way to do that is to create a menu that will appear when the user right-clicks in the relevant control. The menu can also support other common commands, such as Select All.

Would it be useful if I give you some help in doing that?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Yes Mike thats exactly what i want to do.... its as if the user pressed the enter key... thanks
 
IF you want to emulate an action like pasting the clipboard into a specific control and pressing enter afterwards, you would emulate three actions at once:
1. setting focus to the textbox
2. pasting the text
3. pressing ENTER.

If you set a value to anything+chr(13) you don't get the effect of ENTER to trigger leaving the control, just setting the value you even don't have done the first step of setting focus to that textbox. .So even if a chr(13) would trigger the same action as actually pressing the key ENTER, it would be done at the button, which has focus as it's clicked, not at the textbox.

If you do the normal paste action you also don't get an automatic ENTER. There is one case you get an automatic advancing of the focus to the next control: If the textbox has a max number of characters and the clipboard text has exactly that length. But then you neither need to add a CHR(13) nor need to emulate pressing ENTER.

It's again very essential what you want to do why, because I'm sure there is some much simpler way to have the UI you want. I see you want to introduce a shortcut for a user to need less key presses. Well, actually you introduce the need to use the mouse and click on the paste button, using TABs to get to the textbox, CTRL+V and ENTER could be done faster by the user when he's not at using the mouse anyway. And when you have something in the clipboard you want to past you usually are using the keyboard and have just used CTRL+C to copy or CTRL+X to cut something for pasting.

I don't see much benefit from a paste button, but it's simple to do the 3 actions you actually need to do in code:
Code:
this.parent.text40.Setfocus()
Keyboard'{CTRL}+V{ENTER}' PLAIN CLEAR

Another thing you could add in code to the text40 textbox so that pasting the clipboard to it also acts like pressing ENTER right afterwards is the better solution in my opinion. In text40.Keypress event put:
Code:
LPARAMETERS nKeyCode, nShiftAltCtrl
IF nShiftAltCtrl=2 AND nKeyCode=22
   && Paste by CTRL+V 
   Keyboard '{ENTER}'
ENDIF
This makes text40 react to a paste with adding ENTER itself. For sake of tabbing to the next control in tab order a KEYBOARD '{TAB}' is even more appropriate.
The textbox also behaves normal when the user doesn't paste in text but types letter by letter.
So this could also be put into a base textbox class and let every application textbox have this new ENTER/TAB behavior, if ou use classes and let all your form textboxes be that class or a derived class of it.

You can also combine this, have the code for text40 and then still have a paste button which simply sends a paste action to text40 by:
Code:
this.parent.text40.Setfocus()
Keyboard('{CTRL}+V')
The ENTER is then added by text40 no matter if the paste comes from the paste button or by the user actually using CTRL+V to paste into text40 without using the paste button.

Overall I just wonder why that paste button, it's very special when it just works on text40. Usually where a user pastes is up to himself by setting focus first. As said that in itself could be done simpler and faster than a click on your shortcut button. The button also can be "clicked" by tabbing to it and pressing SPACE. But then it's still questionable whether you first arrive to text40 and could CTRL+V there or arrive on the paste button and SPACE.

I think we've had this kind of discussion much earlier in one of your first threads about automating the user interface and I concluded the benefit of what you tried to automate are very neglectable, if they don't even hurt.

If I think of optimizing a paste action then I'd think about how to even not need it at all. A paste does follow a copy/cut, so the question becomes why does something need to be copied at all? If you can manage to take the same input twice the whole action of copy&paste becomes obsolete.

Chriss
 
Chriss said:
I'm sure there is some much simpler way to have the UI you want.

I agree. My preference would be to use the built-in shortcuts (CTRL+C, etc.) as per my previous post. That way, you give the user the interface that they are already familiar with. And you can easily make it generic, so that it works the same with all your editable controls, with no extra effort on your part.

In summary, here is what I suggest:

1. Create a new shortcut menu. For example, from the Project Manger, select Other -> Menus -> New.

2. When prompted, choose Shortcut rather than Menu.

3. In the menu designer, click on the first row under "Prompt", then click on Insert Bar.

4. In the next dialogue, choose Copy.

5. Go to the next row. Repeat the above, but this time choose Cut.

6. Repeat, choosing Paste.

7. Repeat for any other items you would like to have in the menu.

8. From the main VFP menu bar, choose Menu -> Generate.

9. When prompted, save the menu. Name it, say, EditMenu.

10. Confirm that you want to generate the menu. It will be named, for example, EditMenu.MPR.

11. Open your form in the form designer. In the right-click event of your text box, write this code: [tt]DO EditMenu.MPR[/tt] (or whatever you named it; if the MPR file is not in the search path, precede its name with its path).

12. Now, when you run the form, the user will be able to right-click on the textbox and choose to cut, copy, paste, etc. Better still, they will also be able to use the standard shortcut keys (CTRL+C, etc.) without having to right-click.

13. Ideally, the final step will be to place the code (as per Step 11, above) in the right-click event of your base textbox class. That way, every textbox in your application will inherit the behaviour.

Although this means more steps than your existing method, I think you will agree that the result will be a better UI, and more in line with what the user expects from Windows applications.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mandy,

of course you can always copy the contents of the clipboard to a variable and do what ever you want with it from that point on

EG.
MyStringVar = _ClipText

MyStringVar can then be assigned to a control value, table, cursor - used as part of an expression or comparison

My 2 Pennyworth for what it's worth

I've lurked here for a long time and thought it time to contribute

VFP Programmer since 1985, before that Basic on Mainframes, now also C# .Net in all its forms and SQL / SSRS

Regards and respect to all


 
Just by the way, if this is for a device with touch display only, I could understand why you'd neither want to have a context menu nor a keyboard oriented interface.
Just a thought I had, if it's the real reason behind our question, then please tell such things, the context matters for best advice.

Anyway, for such matters what would fit a touch application is a toolbar. It has buttons you could make large enough for good touch usage and it has one big advantage to any normal buttons you put on forms: When you click or touch such a button the focus on whatever control has the focus on whatever form of the application currently activated will stay in focus.

That way such a toolbar paste button would only need its click event to be
Code:
Keyboard '{CTRL}+V'

And then I'd also decide on a per control basis whether the control itself processes a paste action with an automatic ENTER or TAB, not make it paste button default action.
A toolbar with standard buttons also exists as class _standardtoolbar of Home()+"wizards\_framewk.vcx", but you'd not be able to use it standalone, it's embedded in the usage of the application wizard to create the whole application. In it's click something much more complicated happens which in the end just causes the standard menu PASTE.

But what you could do is create your own toolbar buttons with at least the three copy, cut and paste buttons. their icons are very commonly used:
touchtoolbar_olfuqq.png

cut, copy, paste

All they need in code are
Code:
Keyboard '{CTRL}+X'
Code:
Keyboard '{CTRL}+C'
Code:
Keyboard '{CTRL}+V'
And putting them into a toolbar makes them usable without changing focus off of whatever form/control has the focus right now.

Creating a toolbar is described in the help topic "How to: Define a Toolbar Class", which you can search in the help or find in

Again, just a guess you might want the button as interface for touch users. But then it also would be an idea for a classic desktop situation, too. Because that "magic" feature of toolbars to work independent of the focus the usual application window/child window (form)/control hierarchy defines - that feature is also helpful in a normal desktop situation, not only for touch usage. Which is why I don't even wait for you to tell me whether it is for touch usage or not.


Chriss
 
Hi Colin, Chris and Mike... Thank you everything that youve suggested, it all worked for my application... I found the thing that would work best with my project using all your insights... my project is almost complete... just a little polishing... God bless everyone....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top