event.VK_ENTER with confirmation dialogue

Hello,

I have Numeric Text Field which has event on keyReleased:

if event.keyCode == event.VK_ENTER: value = event.source.floatValue tagPath=event.source.TagPath if system.gui.confirm('Are You sure?', 'Confirm'): system.tag.writeToTag(tagPath, value) else: event.source.floatValue=system.tag.getTagValue(tagPath)

When I change the value of this Numeric Text Field and press Enter, confirmation dialogue pops up.
If I use mouse click to operate ‘Yes’ ‘No’ buttons on confirmation dilaogue, everything works fine.
But if I use Enter on confirmation dialogue, my event script works again. It means that event on confirmation dialogue is actually Numeric Text Field event.
Is it possible to separate those events somehow?

Is there a reason you have the script on the key released event? If not then try putting the script under the key pressed event. The key pressed event should avoid the behavior that you’re currently seeing.

Thanks.
But unfortunatelly it doesn’t work as it should under key pressed.
In this case if I enter value and confirm with Enter key, value will be displayed in Numeric text field, but will not be written to tag. If I enter some other value and confirm, previous input will be written.

What you’re doing is inherently risky.

What happens if they alter the value and tab away instead of hitting enter?

I think you’d be better off designing some sort of confirm-before-write template that used a display field, a button to enter “edit mode” and a button to commit the write or something like that…