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!

Count keystrokes in VFP

Status
Not open for further replies.

eogvot

Programmer
Mar 11, 2009
9
US
Is there a way to count the number of keystrokes that an individual makes while editing data in a textbox?
I would want to exclude pressing of arrow keys used to move the cursor around within the textbox.

I am attempting to monitor whether individuals are making "significant" changes to the data in the textbox or whether they are simply updating 1 or 2 characters?

Visual FoxPro 7
 
I have many ideas about that.

You can use keypress event, interactivechange. You can also memorize the initial value or use OLDVAL() in case of using buffering and use algorithms like Levenshtein distance or any editing distance function (see to determine the significance of the change, even no matter how many keystrokes were used.

Pick out any one or two or all ideas from this and make something of it.

Chriss
 
To exclude the arrow keys, you can have code in keypress which does a Nodefault for the corresponding nKeyCode and nShiftAltCtrl values.
 
@Tore, I think the OP means they don't want to count the arrow keys as keystrokes, not that they don't want to allow them.

Tamar
 
Yes, and you could also just count a keypress, when the value of the control changes in the interactivechange event following keypress. That unbinds yyyyou from needing to know specific key codes etc. to not count.

Notice, the keypress event allows you to suppress keys, besides counting them, so it happens before the keypress effects the ccontrol value, whereas the interactivechange (and also programmaticchange) happens after an interactive (or programmatic) change of the value.

That makes both of them valuable. Well, as I already said, make use of some or even all of them and edit distance algorithms and you can easily come up with a metric fitting your needs.

Just a bit of caution: CTRL+V is just one keypress and a) can change the value of a control a lot, by whatever is in the clipboard and b) isn't even triggering a keypress event, only the interactivechange. That's a reason keystroke counting won't help you figure out the quality of a change.

Chriss
 
I am attempting to monitor whether individuals are making "significant" changes to the data in the textbox or whether they are simply updating 1 or 2 characters?

Counting the keystrokes won't do that. For example, if the user changes several characters and then changes most or all of them back to what they were before, then you will see many keystrokes but the value won't have greatly changed. Conversely, they could paste an entirely new value, but that would only show one keystroke.

It would be better to save a copy of the original value on entry (in the control's GotFocus), and to compare it to the final value (in the LostFocus).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Gonna be fun though isn't it - what represents a significant change?

Adding a couple of zeros to the end of a quote, or deleting a paragraph?

You might need an api to an AI to decide... B-)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
A good point, Griff. VFP has always lacked a useful function for determining the similarity between two strings. We've got SOUNDEX() and DIFFERENCE(), but they're not really suitable in this case.

I once wrote a VFP implementation of something called the Ratcliff/Obershelp algorithm (look it up), which aims to determine a "similarity score" between two strings. It worked well enough most of the time. It was OK just for comparing two strings, as would be the case here. But I needed to use it to search entire tables, and in that case it was horribly slow and had to be abandoned.

In the (unlikely) event anyone is interested, I published an article about my VFP version in the October 2002 issue of FoxPro Advisor. Unfortunately, I no longer have access to an electronic copy of the article.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top