LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to figure out what is deleted when Delete key is pressed?

Want to know what's being deleted before commit.

 

George Zou
0 Kudos
Message 1 of 12
(3,912 Views)

You could check for a keypress event and read back the text every time a key is pressed (I assume you're talking about a string control) This way you could compare the previous with the new string...

0 Kudos
Message 2 of 12
(3,907 Views)

Because it's before user commit, so when read back, I always get the same thing - the old value, no matter string or numeric control.

 

The purpose is to catch the event when user delete a "."

 

Thanks for reply.

 

George Zou
0 Kudos
Message 3 of 12
(3,906 Views)

-> don't use the commit event: in your EVENT_KEYPRESS case, check for 'Enter' to perform the action of your COMMIT case; there is a nice sample called multikey that visualizes key entries such as DELETE or ENTER

 

hth, Wolfgang

0 Kudos
Message 4 of 12
(3,903 Views)

The problem isn't catch the DELETE keypress event, but in that event, what will be deleted.

 

 

George Zou
0 Kudos
Message 5 of 12
(3,898 Views)

well, my idea was to monitor the keypress event using GetKeyPressEventCharacter; if the keypress event is due to a regular character or a number, add the character to your string and save it; this way you will assemble your text or number character by character; if a DELETE is entered, look up the saved string; you also need to keep track of the cursor position; if a left arrow is entered, the position is reduced by one etc; if you enter a regular character, the position is increased by one... once a DELETE is recognized, you can get the deleted character from the tracked cursor position and the saved string

Message 6 of 12
(3,895 Views)

Thought about all this.

The problem is tracking cursor position.  It's not blank to start with. It's hard to tell the cursor position in left click event.

 

Thank you so much for reply.

 

George Zou
0 Kudos
Message 7 of 12
(3,892 Views)

When a key is pressed you get an EVENT_KEYPRESS and then an EVENT_VAL_CHANGED (assuming the keypress was not swallowed). Just watch for the delete key in the keypress event, save the text of the control pre-deletion, then set a flag letting your program know that the next EVENT_VAL_CHANGED is coming immediately after a delete. Then you can get the post-deletion string and compare the two.   

Kevin B.
Message 8 of 12
(3,878 Views)

That only apply to a string control.  What if it's a numeric control?

Thanks for reply.

 

George Zou
0 Kudos
Message 9 of 12
(3,870 Views)

I can't think of anyway this could be done inside a numeric control because as you pointed out there's no EVENT_VAL_CHANGED generated on keypress (until the value is committed). There's also the issue that GetCtrlVal would return value 2.0 whether the text in the control when it was commited was "2" or "2.0000000" so you couldn't tell necessarily if the decimal had been deleted by the user. I guess I'm not entirely sure I understand why you need this functionality in a numeric control. Knowing that might give some an alternatives for you.

 

Since it can't be done in a numeric control, if you absolutely require this ability then you'd have to "fake" a numeric control using a string control. You could check the EVENT_KEYPRESS and have it swallow all characters other than 0-9, '.', '-', Enter, Delete and Backspace. You can always transform the text in this box to a float using the atof() function. You could even place the string control directly over a numeric control leaving only the Inc/Dec arrows visible. When a user clicked on an arrow you'd just need to get the value of the string, increment or decrement based on the numeric's increment value and then store the result of sprintf(buf, "%f", numericVal); back into the string. This is obviously pretty complex and there might be a few issues I'm forgetting but it could be done if you absolutely had to.

 

Kevin B.
0 Kudos
Message 10 of 12
(3,860 Views)