INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Classes and Objects

How can I type characters programmatically, by invoking the keypress event by vgulielmus
Posted: 13 Feb 14

Unlike other events (click or interactivechange), if keypress is simply invoked, it is triggered but the characters are not "typed".
But with a little trick, this can be surpassed.

Add a third parameter (logical) in the keypress event .
If this third parameter is .T., then call DODEFAULT() followed by =This.Value.

CODE --> Foxpro

PUBLIC ofrm
ofrm=CREATEOBJECT("MyForm")
ofrm.show()

DEFINE CLASS MyForm as Form
	ADD OBJECT txt as MyText 
	ADD OBJECT cmd as CommandButton WITH left=150,Caption='Select any row from grid and click',Autosize=.T.
	ADD OBJECT grd as grid WITH top=50
	PROCEDURE init
		LOCAL lni
		* Preparing the grid
		CREATE CURSOR cChar (cChar C(10))
		FOR lni=1 TO 5
			INSERT INTO cChar values (CHR(64+m.lni))
		NEXT
		INSERT INTO cChar values ('Two words')
		GO TOP 
		This.grd.RecordSource='cChar'
		This.grd.column1.width=100
	ENDPROC
	PROCEDURE cmd.click
		LOCAL lni,lcStr
		lcStr=ALLTRIM(cChar.cChar)
		FOR lni=1 TO LEN(m.lcStr)
			ThisForm.txt.Keypress(ASC(SUBSTR(m.lcStr,m.lni,1)),0,.T.)
		NEXT
	ENDPROC 
ENDDEFINE
*********************
* Text box class
*********************
DEFINE CLASS MyText as TextBox
	PROCEDURE keypress
		LPARAMETERS nKey,nShift,lraised
		IF lraised
			DODEFAULT(nKey,nShift)
			=This.value
		ENDIF
	ENDPROC
ENDDEFINE 

Vilhelm-Ion Praisach

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close