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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trapping CTL characters in textbox/editbox

Status
Not open for further replies.

OldxBaser

Programmer
Nov 5, 2009
24
I am trying to trap the Ctrl + A, Ctrl + V in a textbox, and it seems that the event is not triggered (also for some other ctrl + key combinations).
But I can trap them if the control is an editbox.

Is this a VFP bug? Is there a way around it?
 
Are you using base classes? In my test both controls keypress event is not triggered by ctrl+a and ctrl+v. Those are system keys for select all and paste.

What do you want to achieve?
If controls should not allow selecting, copying and pasting, set enabled=.f.
If you want to allow selecting and copying, but not pasting, set readonly=.t.

Bye, Olaf.
 
Here's the code I used to check. It might have to do with _screen, but _screen.keypreview is .f., I don't see how you could trap ctrl+a or v.

Code:
With _screen
.AddObject("text1","mytext")
.AddObject("edit1","myedit")
.text1.left = 300
.text1.visible = .t.
.edit1.top = 50
.edit1.left = 300
.edit1.visible = .t.
EndWith

Define Class mytext as textbox
   Procedure Keypress()
      LPARAMETERS nKeyCode, nShiftAltCtrl
      Activate Screen
      ? nKeyCode, nShiftAltCtrl
   EndProc
EndDefine

Define Class myedit as editbox
   Procedure Keypress()
      LPARAMETERS nKeyCode, nShiftAltCtrl
      Activate Screen
      ? nKeyCode, nShiftAltCtrl
   EndProc
EndDefine

Running that, writing into controls displays the keypress parameter value on _screen, but not in the case of such system keys, they are hotkeys for the Edit sysmenu items.
What you could do anyway is override they hotkeys with ON KEY, it's not recommendable, but might be sufficiently working for you. You can also override they keys by defining a context/popup menu with items using these hotkeys, it doesn't even have to be displayed.

Bye, Olaf.
 
I can confirm Olaf's results. I did a similar test, but using a form rather than _SCREEN (I wouldn't expect that to make any differences though).

With a menu active, you can't trap any of the CTRL+letter combinations that are the same as shortcuts in the menu. So, with the default system menu, you can't trap CTRL+R (shortcut for Redo), CTl+O ("open" dialogue"), CTRL+B (breakpoints), and so on.

If you hide the menu (for example, with SET SYSMENU TO), those key combinations become trappable. But, in my tests, although I could trap CTRL+A, CTRL+Z, CTRL+X, CTRL+C and CTRL+V, they still executed their built-in functions (unless I also issued NODEFAULT).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks Olaf,
This is what I want to happen.
The control is editable but if the textbox has a particular value, I want to disable CTL-A, like in Google Gmail Subject textbox when the initial word "Subject" is still there.

Roy
 
Thanks Mike ... tried that and it solved my problem
Also ... thanks Olaf for taking the time to respond.
 
Well, you could also use programmaticchange and interactivechange and set enabled = .f. in the moment you got some keyword in your textbox/editbox Value. That would be the better choice in my eyes. Even though mike said the hotkeys still keep their functionality, it's good to have the edit menu or context menu with the standard select, cup, copy paste items. Solve a local problem local.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top