# Perspective: Object onKeyPress Event

**URL:** <https://forum.inductiveautomation.com/t/perspective-object-onkeypress-event/40685>\
**Category:** Ignition\
**Tags:** ignition80, perspective, scripting\
**Created:** [November 16, 2020, 12:10pm UTC](https://forum.inductiveautomation.com/t/perspective-object-onkeypress-event/40685 "2020-11-16T12:10:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [November 16, 2020, 12:10pm UTC](https://forum.inductiveautomation.com/t/perspective-object-onkeypress-event/40685/1 "2020-11-16T12:10:44Z")

</div>

Hello Everybody,

I use 8.1.0 v of Ignition  
I have one problem.  
Is it okay that Tree Element onKeyPress Event does not work?  
I am talking about this:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/8/c8e93dee422ac881a1fb436a2cde80d2434941c0.png)  
I just print text to Output Console when any key was pressed…

```auto
system.perspective.print('Pressed')

```

and this script does not work for me…

---

<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 16, 2020, 4:09pm UTC](https://forum.inductiveautomation.com/t/perspective-object-onkeypress-event/40685/2 "2020-11-16T16:09:03Z")

</div>

For any Perspective component, the onKeyPress Event requires that the component have focus (otherwise any component with a similar event would also fire). I don’t believe that the tree ever actually gets focus though, because it isn’t an input. So I wouldn’t expect that event to do anything when used as part o the Tree component.

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [November 17, 2020, 6:51am UTC](https://forum.inductiveautomation.com/t/perspective-object-onkeypress-event/40685/3 "2020-11-17T06:51:21Z")

</div>

Thanx for Your Replay.

It’s sad, because I need this action( 😟

---

<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 17, 2020, 3:53pm UTC](https://forum.inductiveautomation.com/t/perspective-object-onkeypress-event/40685/4 "2020-11-17T15:53:19Z")

</div>

There is development underway for a key-listener for Sessions. It could possibly work for you, depending on what you’re trying to do. It captures key strokes within the session and allows for firing actions based off of the keystrokes. You would need some logic like this within the script action for the upcoming Event/Listener:

```auto
modification_keys = ['w', 'a', 's', 'd']
if event.page.props.path == 'some/arbitrary/path' and event.key in modification_keys:
    # do something to the tree with event.key

```

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [November 18, 2020, 10:32am UTC](https://forum.inductiveautomation.com/t/perspective-object-onkeypress-event/40685/5 "2020-11-18T10:32:42Z")

</div>

> [@cmallonee](#):
>
> depending on what you’re trying to do

Thanx for Your Replay!

I just wanted to select the object from menu, press ENTER and it opens Vision Window for object. That's all.  
But... I found another solution for this: I just use for it 👉 **onContextMenu** 👈 Event.

But... now I know this Information You posted and I'll try it next time for sure! 🙏

---

<div class="post-metadata">

**Author:** ![ken.maze](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken.maze/32/85876_2.png) [@ken.maze](https://forum.inductiveautomation.com/u/ken.maze)\
**Post date:** [November 16, 2023, 5:32pm UTC](https://forum.inductiveautomation.com/t/perspective-object-onkeypress-event/40685/7 "2023-11-16T17:32:49Z")

</div>

Did this Event/Listener ever get implemented? I don't see it in the manual, but I'm also terrible at finding food in the fridge, so I probably missed this in the manual as well.

Thanks

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [November 16, 2023, 5:43pm UTC](https://forum.inductiveautomation.com/t/perspective-object-onkeypress-event/40685/8 "2023-11-16T17:43:12Z")

</div>

> [@ken.maze](#):
>
> ... but I'm also terrible at finding food in the fridge ...

You're just not hungry enough.

---

<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:** [November 16, 2023, 5:49pm UTC](https://forum.inductiveautomation.com/t/perspective-object-onkeypress-event/40685/9 "2023-11-16T17:49:28Z")

</div>

[https://docs.inductiveautomation.com/display/DOC81/Perspective+Session+Event+Scripts#PerspectiveSessionEventScripts-Keystroke](https://docs.inductiveautomation.com/display/DOC81/Perspective+Session+Event+Scripts#PerspectiveSessionEventScripts-Keystroke)

---

<div class="post-metadata">

**Author:** ![ken.maze](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken.maze/32/85876_2.png) [@ken.maze](https://forum.inductiveautomation.com/u/ken.maze)\
**Post date:** [November 16, 2023, 8:22pm UTC](https://forum.inductiveautomation.com/t/perspective-object-onkeypress-event/40685/10 "2023-11-16T20:22:01Z")

</div>

That works great! Thanks, I was worried I would only find bologna, but I found some good stuff instead 🙃
