# Perspective Enter Key Action

**URL:** <https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [August 30, 2025, 12:54am UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289 "2025-08-30T00:54:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [August 30, 2025, 12:54am UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289/1 "2025-08-30T00:54:09Z")

</div>

Hi all,

I’ve got a button that sends a message to a handler on the root container. The results of the message handler is a query that searches for a part and sets a custom property, to which a table is bound.

This works fine.

I used this same message for pressing the Enter key. But, I do not get any query results. So, I bound a label to a custom property, and set this property via the root message handler, and it works both with the button click and Enter key events.

Any ideas why this might happen?

Thanks,

mike

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 30, 2025, 1:55am UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289/2 "2025-08-30T01:55:59Z")

</div>

On what component did you configure the keyboard event?

(Share more details, or export an example view.)

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [September 1, 2025, 8:34pm UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289/3 "2025-09-01T20:34:25Z")

</div>

Right, I did forget that.  
The keyboard event is configured on a parent flex container of the button.

Root → flex → tab container→ flex → flex with keyboard event → coord → button that sends message.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 2, 2025, 12:26am UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289/4 "2025-09-02T00:26:55Z")

</div>

Button and key event code?

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [September 2, 2025, 4:14pm UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289/5 "2025-09-02T16:14:48Z")

</div>

Edit - specific key event code:

```python
	if event.key =='Enter':
		message = "inv_parts_query"
		payload = {}
		system.perspective.sendMessage(message, payload)

```

Button event code:

```python
	message = "inv_parts_query"
	payload = {}
	system.perspective.sendMessage(message, payload)

```

And the message handler:

```python
	self.custom.lbl_msg = "message test"
	catalog = self.custom.stock_data_filter.catalog
	master = self.custom.stock_data_filter.master
	partNum = self.custom.stock_data_filter.partNum
	desc = self.custom.stock_data_filter.desc
	category = self.custom.stock_data_filter.category
	area = self.custom.stock_data_filter.area
	classification = self.custom.stock_data_filter.classification
	bin = self.custom.stock_data_filter.bin
	stock = self.custom.stock_data_filter.stock_level
	stocked = self.custom.stock_data_filter.active
	
	if stock != 3:
		if area != 0:
			namedQuery = "INV/CurrentLessThan"
			params = {"p_Stock":stock, "p_Area":area}
			system.perspective.print(params)
			self.custom.stock_tbl_data = system.db.runNamedQuery(namedQuery,params)
		else:
			# if no area is selected...
			self.custom.lbl_msg = "You must select an Area first."
			self.custom.lbl_vis = True
	else:
		params = {"p_Bin":bin, "p_Class":classification, "p_Category":category, "p_Desc":desc, 
			"p_PartNum":partNum, "p_Master":master, "p_Cat":catalog, "p_Area":area, "p_Stocked":stocked}
		namedQuery = "INV/Item_Details_Filter"
		self.custom.stock_tbl_data = system.db.runNamedQuery(namedQuery,params)	

```

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [September 2, 2025, 4:30pm UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289/6 "2025-09-02T16:30:39Z")

</div>

I don’t see any key event code…

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [September 2, 2025, 5:00pm UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289/7 "2025-09-02T17:00:33Z")

</div>

Edited for clarification. Thanks.

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [September 2, 2025, 5:06pm UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289/8 "2025-09-02T17:06:28Z")

</div>

What is the key event handler attached to? Are you sure it’s firing? I would put a `system.perspective.print()` in there to verify it. If it’s firing but the message handler isn’t hearing the message, then perhaps it’s a scope issue. You aren’t providing one, and the default is `page`.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [September 2, 2025, 5:16pm UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289/9 "2025-09-02T17:16:28Z")

</div>

In the OP:

> [@mdemaris](#):
>
> I used this same message for pressing the Enter key. But, I do not get any query results. So, I bound a label to a custom property, and set this property via the root message handler, and it works both with the button click and Enter key events.

This label confirmed that the message handler fired with the key event and button event.

This is where the key event is attached:

> [@mdemaris](#):
>
> Root → flex → tab container→ flex → flex with keyboard event → coord → button that sends message.

The message handler is on the root container.

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [September 2, 2025, 5:24pm UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289/10 "2025-09-02T17:24:12Z")

</div>

So the key event is attached to the button? That will only work when the button has focus. That will be true of whatever you attach it to. I would say to invoke `self.focus()` on the button in an `onStartup` event handler, but that is not guaranteed to work, since other parts of the view may steal focus when they get rendered. Perspective doesn’t have an `onLoad` handler that would fire after everything in the view is done rendering, something I have requested:

> **[Perspective view onLoad event that fires when the view is done loading |...](https://ideas.inductiveautomation.com/ignition-features-and-ideas/p/perspective-view-onload-event-that-fires-when-the-view-is-done-loading)**
>
> This would be the only clean way of ensuring that, for example, an input .focus() would execute at the right time... https://forum.inductiveautomation.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [September 2, 2025, 5:29pm UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289/11 "2025-09-02T17:29:04Z")

</div>

Ok, I tested a few more things, and it appears that there are two (2) components out of 8 or 9 that do not work with the query when I press the Enter key.

The two components are numeric text fields. I seem to recall asking this question a long time ago, now that I have come back to this project and have narrowed it down again...

No, the key event is held on a flex container, two levels up from the button.

Edit: So the issue is the numeric text fields. I will go back and look for my old thread on this and see what the end result was.

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [September 2, 2025, 5:33pm UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289/12 "2025-09-02T17:33:46Z")

</div>

If the numeric text fields have focus when you press Enter, then they could be preventing the flex that has the key event handler from hearing it.

You could add the same handler to the inputs themselves, or you might want to try a Session Event Keystroke handler. I’ve never used it, but I would guess it isn’t tied to the focus of any particular page element.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [September 2, 2025, 5:39pm UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289/13 "2025-09-02T17:39:13Z")

</div>

Ah, I think I see what is happening. After entering a value, I must move the focus to another component first, then press Enter.

It will not work if I click somewhere in the container, i.e. not on an interactive component, but some other component must get the focus for the numeric field to, I assume, accept the input value and "transmit" to the bound property...

Perhaps this could be resolved in an update?

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [September 2, 2025, 5:46pm UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289/14 "2025-09-02T17:46:35Z")

</div>

Not sure I follow completely, but that sounds like this issue:

> **[Don't Reject Updates on Numeric Entry Field | Ignition Features and Ideas |...](https://ideas.inductiveautomation.com/ignition-features-and-ideas/p/dont-reject-updates-on-numeric-entry-field)**
>
> The Perspective Numeric Entry Field currently does not allow a configuration that updates the value before focus is lost or ENTER is pressed.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [September 2, 2025, 5:53pm UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289/15 "2025-09-02T17:53:53Z")

</div>

Right. So, moving the focus to another component before sending the message is what needs to happen. I put a short `sleep` statement in, but I seem to remember someone more knowledgeable stating that is not good practice. All I need is a short delay so the input value gets captured before running the rest of the script.

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [September 2, 2025, 6:26pm UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289/16 "2025-09-02T18:26:36Z")

</div>

Yeah, `sleep` is never a good idea. I always try to avoid using a delayed reaction, but sometimes it seems necessary, in which case I use a `Timer`:

```python
from threading import Timer

def doSomething(self):
	...

Timer(0.5, doSomething, [self]).start()

```

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [September 2, 2025, 10:18pm UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289/17 "2025-09-02T22:18:44Z")

</div>

I tried this, and I think the Timer does not actually wait to call the function. Seems like it happens right away.

```python
def runAction(self, event):
	from threading import Timer

	def udf_partsQuery():
		message = "inv_parts_query"
		payload = {}
		system.perspective.sendMessage(message, payload)
		
	if event.key == 'Enter':
		self.getSibling("btn_Search").focus()
		
		Timer(0.1, udf_partsQuery()).start()
	#	Timer(0.1, udf_partsQuery, [self]).start()

```

Edit: Never mind, don't include the parens on the function!

Edit 2: No dice on the query running. I added a line to change the background color of a button just below the message call, and I got nothing to happen.

---

<div class="post-metadata">

**Author:** ![David\_Stone](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/david_stone/32/79749_2.png) [@David\_Stone](https://forum.inductiveautomation.com/u/David_Stone)\
**Post date:** [September 2, 2025, 10:27pm UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289/18 "2025-09-02T22:27:50Z")

</div>

> [@mdemaris](#):
>
> `system.perspective.sendMessage`

Did you try forcing page scope and ensure that the handler is listening to page scope?

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [September 2, 2025, 11:01pm UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289/19 "2025-09-02T23:01:12Z")

</div>

```python
def runAction(self, event):
	from threading import Timer

	def udf_partsQuery():
		message = "inv_parts_query"
		payload = {}
		system.perspective.sendMessage(messageType=message, payload=payload, scope='page')
		self.parent.parent.parent.getChild("flx_InputArea").custom.bg01 = '#FFFF00'
		
		pu_id = 'partsQuery'
		view = 'Page/misc/Message_PU'
		msg = e
		params = {'pu_id': pu_id, 'msg':msg}
		system.perspective.openPopup(pu_id, view, params)
	
		
	if event.key == 'Enter':
		self.getSibling("btn_Search").focus()
		
		Timer(1.0, udf_partsQuery).start()

```

So, this code is running on a numeric text field, I don't think I made that clear. The button gets the focus, good. **IF** I move the backgound color line to the top of the function, the color will change, but not in it's current position in the code.  
I changed the message handler to display a message, as I did earlier, and it is not firing. For some reason, the `sendMessage` is not working in this context.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 2, 2025, 11:06pm UTC](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289/20 "2025-09-02T23:06:02Z")

</div>

> [@pturmel](#):
>
> export an example view

We're going in circles. Boil it down to a stand-alone reproducer and share it.

[Next page](https://forum.inductiveautomation.com/t/perspective-enter-key-action/110289.md?page=2)
