# Binding PC Keyboard buttons to buttons in Ignition

**URL:** <https://forum.inductiveautomation.com/t/binding-pc-keyboard-buttons-to-buttons-in-ignition/37694>\
**Category:** Ignition\
**Tags:** ignition80, vision\
**Created:** [August 13, 2020, 6:49pm UTC](https://forum.inductiveautomation.com/t/binding-pc-keyboard-buttons-to-buttons-in-ignition/37694 "2020-08-13T18:49:58Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhicks1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mhicks1/32/14121_2.png) [@mhicks1](https://forum.inductiveautomation.com/u/mhicks1)\
**Post date:** [August 13, 2020, 6:49pm UTC](https://forum.inductiveautomation.com/t/binding-pc-keyboard-buttons-to-buttons-in-ignition/37694/1 "2020-08-13T18:49:58Z")

</div>

Good Afternoon, I have been asked if it is possible to bind keys from the PC Keyboard (F3 for example) to a button on an Ignition Screen. For example, if we are saving a recipe, you could click the "Save" button on the Ignition screen but also if you press F3 it would accomplish the same function.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [August 13, 2020, 6:53pm UTC](https://forum.inductiveautomation.com/t/binding-pc-keyboard-buttons-to-buttons-in-ignition/37694/2 "2020-08-13T18:53:04Z")

</div>

Yes you should be able to using `.doClick()`. In a client event script, keystroke event, add a script like so

```auto
main = system.gui.getWindow("your Window")

button = main.getRootContainer().getComponent("yourButton")
button.doClick()

```

---

<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:** [August 13, 2020, 6:57pm UTC](https://forum.inductiveautomation.com/t/binding-pc-keyboard-buttons-to-buttons-in-ignition/37694/3 "2020-08-13T18:57:20Z")

</div>

A much more reusable approach - put any and all non-trivial business logic into project scoped scripts. Have keystroke scripts _or_ button `actionPerformed` simply call those scripts.

---

<div class="post-metadata">

**Author:** ![mhicks1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mhicks1/32/14121_2.png) [@mhicks1](https://forum.inductiveautomation.com/u/mhicks1)\
**Post date:** [August 13, 2020, 6:58pm UTC](https://forum.inductiveautomation.com/t/binding-pc-keyboard-buttons-to-buttons-in-ignition/37694/4 "2020-08-13T18:58:10Z")

</div>

So “your Window” would be the window the button resides  
“yourButton” would be the button I want to simulate with an actual keyboard stroke.  
button.doClick() would be the key i choose to use like (F3) ?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [August 13, 2020, 6:58pm UTC](https://forum.inductiveautomation.com/t/binding-pc-keyboard-buttons-to-buttons-in-ignition/37694/5 "2020-08-13T18:58:16Z")

</div>

I thought of that as an alternative to `.doClick()`, just call the same project script from either the button or the keystroke.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [August 13, 2020, 7:02pm UTC](https://forum.inductiveautomation.com/t/binding-pc-keyboard-buttons-to-buttons-in-ignition/37694/6 "2020-08-13T19:02:27Z")

</div>

As @paul-griffith mentioned, it would be best to put the script into the project script library. Then call the script from the button or the keystroke. IE

```auto
project.myScript

```

As far as the `.doClick()` goes, the entire script I gave would be in the keystroke event script

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/f/ff24575db7d50b44eb0cee2b6c4cf9bc40a296fb.png)

---

<div class="post-metadata">

**Author:** ![mhicks1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mhicks1/32/14121_2.png) [@mhicks1](https://forum.inductiveautomation.com/u/mhicks1)\
**Post date:** [August 13, 2020, 7:07pm UTC](https://forum.inductiveautomation.com/t/binding-pc-keyboard-buttons-to-buttons-in-ignition/37694/7 "2020-08-13T19:07:30Z")

</div>

That seems very simple and straight forward. so in the case you presented, the F3 button would only have one task. By adding additional script, it could do tasks on other screens, correct?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [August 13, 2020, 7:14pm UTC](https://forum.inductiveautomation.com/t/binding-pc-keyboard-buttons-to-buttons-in-ignition/37694/8 "2020-08-13T19:14:40Z")

</div>

You may want to check to make sure the window is open before you try to run a script involving that window. Probably would involve [system.gui.getOpenedWindowNames()](https://docs.inductiveautomation.com/display/DOC79/system.gui.getOpenedWindowNames)

```auto
windows = system.gui.getOpenedWindowNames()
if 'window1' in windows:
  do this...

```

This F3 keystroke is a project event script, so it will only do this for the project. Every project could have an F3 event that did something different, but for different windows in the same project you need to check which window is open etc, before running the script.

---

<div class="post-metadata">

**Author:** ![mhicks1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mhicks1/32/14121_2.png) [@mhicks1](https://forum.inductiveautomation.com/u/mhicks1)\
**Post date:** [August 13, 2020, 7:59pm UTC](https://forum.inductiveautomation.com/t/binding-pc-keyboard-buttons-to-buttons-in-ignition/37694/9 "2020-08-13T19:59:19Z")

</div>

Got it. Thank you very much for your help.

---

<div class="post-metadata">

**Author:** ![Koussaila\_Fekroune](https://avatars.discourse-cdn.com/v4/letter/k/96bed5/32.png) [@Koussaila\_Fekroune](https://forum.inductiveautomation.com/u/Koussaila_Fekroune)\
**Post date:** [May 30, 2024, 3:02pm UTC](https://forum.inductiveautomation.com/t/binding-pc-keyboard-buttons-to-buttons-in-ignition/37694/10 "2024-05-30T15:02:08Z")

</div>

ajouter un script sur en bouton dans ignition pour cliquer sur le bouton windows de clavier

---

<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:** [May 30, 2024, 3:46pm UTC](https://forum.inductiveautomation.com/t/binding-pc-keyboard-buttons-to-buttons-in-ignition/37694/11 "2024-05-30T15:46:24Z")

</div>

> [@Koussaila\_Fekroune](#):
>
> add a script on button in ignition to click on windows keyboard button

> **[Robot (Java SE 17 & JDK 17)](https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/java/awt/Robot.html)**
>
> declaration: module: java.desktop, package: java.awt, class: Robot
