# Force 'mouseClicked' action on numeric textfield component via script

**URL:** <https://forum.inductiveautomation.com/t/force-mouseclicked-action-on-numeric-textfield-component-via-script/33998>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [April 17, 2020, 6:13am UTC](https://forum.inductiveautomation.com/t/force-mouseclicked-action-on-numeric-textfield-component-via-script/33998 "2020-04-17T06:13:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [April 17, 2020, 6:13am UTC](https://forum.inductiveautomation.com/t/force-mouseclicked-action-on-numeric-textfield-component-via-script/33998/1 "2020-04-17T06:13:48Z")

</div>

How can I force a `mouseClicked` action on a numeric textfield component via script?

e.g. to simulate an `actionPerformed` event for a button I would call:  
`button.doClick()`

Reason is, touchscreen mode is enabled and I want to force the touchscreen numeric keypad to open to edit the component value, but via script…

This post looks like it’s on the money, but it seems that the `getActionListeners` method has been made private… Also I wouldn’t know how to create the `ActionEvent` to pass into it.

> <https://stackoverflow.com/questions/26927483/simulate-button-click-according-to-jtextfields-changes>

```auto
//JAVA CODE
// Does not appear in the UI
for(ActionListener a: mybutton.getActionListeners()) {
    a.actionPerformed(yourActionEvent);
 }

```

---

<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:** [April 17, 2020, 11:30am UTC](https://forum.inductiveautomation.com/t/force-mouseclicked-action-on-numeric-textfield-component-via-script/33998/2 "2020-04-17T11:30:51Z")

</div>

You might need to use Java’s [Robot](https://docs.oracle.com/javase/8/docs/api/java/awt/Robot.html) input simulation kit.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [April 17, 2020, 11:32am UTC](https://forum.inductiveautomation.com/t/force-mouseclicked-action-on-numeric-textfield-component-via-script/33998/3 "2020-04-17T11:32:44Z")

</div>

I think there’s some “getFocus” function that may do the same. I think I saw something similar in my app, Ill see if it’s applicable.

Edit: Ok so we do stuff like this to give focus to a component upon opening a form I think it may work for you.

```auto
component = system.gui.getParentWindow(event).getComponentForPath('Root Container.txtCustomerName')
component.requestFocusInWindow()

```

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [April 17, 2020, 12:39pm UTC](https://forum.inductiveautomation.com/t/force-mouseclicked-action-on-numeric-textfield-component-via-script/33998/4 "2020-04-17T12:39:49Z")

</div>

Hmm, well I don’t really like it, but using Robot _does_ work. It feels a bit clunky though, and backfires if the mouse is moved.  
FYI: requesting focus only moves the focus to the component, it doesn’t fire off any click events. I was doing this already, but then when I tried it with touchscreen enabled, it then required an extra tap to open up the keypad.

```auto
#click on the textfield to launch the numeric keypad to stop the user having to click on the component twice
	def clickAgain():
		from java.awt import Robot
		from java.awt.event import InputEvent
		
		r = Robot()
		r.mousePress(InputEvent.BUTTON1_MASK)
		r.mouseRelease(InputEvent.BUTTON1_MASK)
	#delay 500 so that a double-click isn't registered	
	system.util.invokeLater(clickAgain,500)

```

---

<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:** [April 17, 2020, 3:17pm UTC](https://forum.inductiveautomation.com/t/force-mouseclicked-action-on-numeric-textfield-component-via-script/33998/5 "2020-04-17T15:17:42Z")

</div>

…[https://docs.inductiveautomation.com/display/DOC80/system.gui.showNumericKeypad](https://docs.inductiveautomation.com/display/DOC80/system.gui.showNumericKeypad)?
