# Identifier for 'Enter' with onKeyPress event for v8.1.5

**URL:** <https://forum.inductiveautomation.com/t/identifier-for-enter-with-onkeypress-event-for-v8-1-5/48853>\
**Category:** Ignition\
**Created:** [July 14, 2021, 8:08pm UTC](https://forum.inductiveautomation.com/t/identifier-for-enter-with-onkeypress-event-for-v8-1-5/48853 "2021-07-14T20:08:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mleefers](https://avatars.discourse-cdn.com/v4/letter/m/8edcca/32.png) [@mleefers](https://forum.inductiveautomation.com/u/mleefers)\
**Post date:** [July 14, 2021, 8:08pm UTC](https://forum.inductiveautomation.com/t/identifier-for-enter-with-onkeypress-event-for-v8-1-5/48853/1 "2021-07-14T20:08:04Z")

</div>

I am trying to change some parameters using the onKeyPress event with a text field using the enter key as the trigger to make the updates. This worked fine in v8.0.xx. After updating to 8.1.5, it appears that when enter is pressed it returns an empty string or at least that is what it looks like. Below are the if statements that I have attempted to return True for but have not been able to.

```auto
if event.key == 'Enter' or event.Key == 'enter':
if event.key == '':
if event.key == ' ':

```

Example outputs from the output console when simply printing event.key every time a key is pressed:

```auto
15:05:25.706 [Browser Thread: 64239] INFO Perspective.Designer.Workspace - a
15:05:26.390 [Browser Thread: 64239] INFO Perspective.Designer.Workspace - f
15:05:26.790 [Browser Thread: 64239] INFO Perspective.Designer.Workspace - d
15:05:27.178 [Browser Thread: 64239] INFO Perspective.Designer.Workspace - s
15:05:28.300 [Browser Thread: 64239] INFO Perspective.Designer.Workspace -

```

The last line is what is returned when Enter is pressed

---

<div class="post-metadata">

**Author:** ![chandler](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@chandler](https://forum.inductiveautomation.com/u/chandler)\
**Post date:** [July 14, 2021, 8:56pm UTC](https://forum.inductiveautomation.com/t/identifier-for-enter-with-onkeypress-event-for-v8-1-5/48853/2 "2021-07-14T20:56:41Z")

</div>

I think the event.key is the newline character `\n`. so you do something like this:

```auto
if event.key == '\n':
     #Code for Enter pressed

```

I think it should do what you want.

After a little bit of playing around, it seems that the event.key for the “Enter” key is a newline character in the onKeyPressed event, but if I use the onKeyDown event, the event.key is “Enter”. This is on 8.1.1, however.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 14, 2021, 10:15pm UTC](https://forum.inductiveautomation.com/t/identifier-for-enter-with-onkeypress-event-for-v8-1-5/48853/3 "2021-07-14T22:15:04Z")

</div>

It’s `\n`, indeed. I’d recommend using `repr()` to enhance your prints in these scenarios, e.g.:  
`system.perspective.print(repr(event))`

```auto
15:08:18.390 [Browser Thread: 54470] INFO Perspective.Designer.Workspace - {u'type': 'keypress', u'eventPhase': 3L, u'bubbles': True, u'cancelable': True, u'timeStamp': 26735.02999963239, u'defaultPrevented': False, u'isTrusted': True, u'detail': 0L, u'key': '\n', u'location': 0L, u'ctrlKey': False, u'shiftKey': False, u'altKey': False, u'metaKey': False, u'repeat': False, u'charCode': 13L, u'keyCode': 0L, u'which': 13L}

```

---

<div class="post-metadata">

**Author:** ![mleefers](https://avatars.discourse-cdn.com/v4/letter/m/8edcca/32.png) [@mleefers](https://forum.inductiveautomation.com/u/mleefers)\
**Post date:** [July 15, 2021, 12:50pm UTC](https://forum.inductiveautomation.com/t/identifier-for-enter-with-onkeypress-event-for-v8-1-5/48853/4 "2021-07-15T12:50:20Z")

</div>

Thanks for the info. That looks like a handy function!

---

<div class="post-metadata">

**Author:** ![Adarsh\_K](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Adarsh\_K](https://forum.inductiveautomation.com/u/Adarsh_K)\
**Post date:** [June 16, 2023, 9:15am UTC](https://forum.inductiveautomation.com/t/identifier-for-enter-with-onkeypress-event-for-v8-1-5/48853/5 "2023-06-16T09:15:53Z")

</div>

Thanks this helped !
