# OnKeyDown event not working

**URL:** <https://forum.inductiveautomation.com/t/onkeydown-event-not-working/40944>\
**Category:** Ignition\
**Created:** [November 25, 2020, 10:01am UTC](https://forum.inductiveautomation.com/t/onkeydown-event-not-working/40944 "2020-11-25T10:01:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![oisin.gribben](https://avatars.discourse-cdn.com/v4/letter/o/9d8465/32.png) [@oisin.gribben](https://forum.inductiveautomation.com/u/oisin.gribben)\
**Post date:** [November 25, 2020, 10:01am UTC](https://forum.inductiveautomation.com/t/onkeydown-event-not-working/40944/1 "2020-11-25T10:01:59Z")

</div>

Hi,  
We are trying to use the OnKeyDown event to validate a string in a text field but it doesn’t trigger at all.  
Is there a bug with this event?  
I even tried with a simple script

```auto
if len(self.props.text) >= 3:
		self.props.text = "3 chars"

```

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [November 25, 2020, 4:49pm UTC](https://forum.inductiveautomation.com/t/onkeydown-event-not-working/40944/2 "2020-11-25T16:49:19Z")

</div>

It looks like you’re using Perspective, so I’ll chime in.

The onKeyXXXX Events only execute if the component they are attached to is the component which currently has focus.

For example:

1. I have a Text Field with a configured onKeyPress Event.
2. In an active session, I click into the Text Field and press “A”. This will trigger the onKeyXXXX Events as expected.
3. I then click a button elsewhere on the page, and press Enter. The onKeyXXXX Event will not fire because the TextField no longer has focus - the Button does.

Alternatively, you should verify that `props.deferUpdates` is not set to be `true`. If this property is active, `props.text` will not update until AFTER the user applies the current text, and so your condition will actually not happen unless the `props.text` field ALREADY has more than 3 characters when the user begins typing.
