# Client Keystroke Script

**URL:** <https://forum.inductiveautomation.com/t/client-keystroke-script/22289>\
**Category:** Ignition\
**Created:** [February 1, 2019, 2:30pm UTC](https://forum.inductiveautomation.com/t/client-keystroke-script/22289 "2019-02-01T14:30:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kunal.ghule](https://avatars.discourse-cdn.com/v4/letter/k/5daacb/32.png) [@kunal.ghule](https://forum.inductiveautomation.com/u/kunal.ghule)\
**Post date:** [February 1, 2019, 2:30pm UTC](https://forum.inductiveautomation.com/t/client-keystroke-script/22289/1 "2019-02-01T14:30:50Z")

</div>

I not able to add keystroke for F10 (pressed or released). I’m getting a message box saying “Keystroke pressed/Released F10 is reserved”.

I am not able to find any connection for F10 in my project & even in fresh ignition setup i’m getting same error.

Please help.

---

<div class="post-metadata">

**Author:** ![ethomason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ethomason/32/43338_2.png) [@ethomason](https://forum.inductiveautomation.com/u/ethomason)\
**Post date:** [February 1, 2019, 3:10pm UTC](https://forum.inductiveautomation.com/t/client-keystroke-script/22289/2 "2019-02-01T15:10:38Z")

</div>

It’s not reserved by anything in your project specifically, it’s reserved by Ignition itself. F10 is already in use in clients. Can you add a modifier?

---

<div class="post-metadata">

**Author:** ![kunal.ghule](https://avatars.discourse-cdn.com/v4/letter/k/5daacb/32.png) [@kunal.ghule](https://forum.inductiveautomation.com/u/kunal.ghule)\
**Post date:** [February 1, 2019, 3:25pm UTC](https://forum.inductiveautomation.com/t/client-keystroke-script/22289/3 "2019-02-01T15:25:45Z")

</div>

Thank you for reply.  
I won’t be able to use modifiers. I’m migrating existing scada to ignition. Client want to retain existing functionality.

I don’t have any other option than using F10 keystroke.

---

<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:** [February 1, 2019, 4:49pm UTC](https://forum.inductiveautomation.com/t/client-keystroke-script/22289/4 "2019-02-01T16:49:25Z")

</div>

You will have to use a client startup script and manipulate the [`ActionMap`](https://docs.oracle.com/javase/7/docs/api/javax/swing/ActionMap.html) and [`InputMap`](https://docs.oracle.com/javase/7/docs/api/javax/swing/InputMap.html) in the client yourself if you want to “override” the F10 behavior.

---

<div class="post-metadata">

**Author:** ![kunal.ghule](https://avatars.discourse-cdn.com/v4/letter/k/5daacb/32.png) [@kunal.ghule](https://forum.inductiveautomation.com/u/kunal.ghule)\
**Post date:** [February 1, 2019, 5:15pm UTC](https://forum.inductiveautomation.com/t/client-keystroke-script/22289/5 "2019-02-01T17:15:04Z")

</div>

Hello Paul,

Could you please explain, I don’t have much knowledge about it.

---

<div class="post-metadata">

**Author:** ![mrogers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mrogers/32/4110_2.png) [@mrogers](https://forum.inductiveautomation.com/u/mrogers)\
**Post date:** [February 1, 2019, 9:30pm UTC](https://forum.inductiveautomation.com/t/client-keystroke-script/22289/6 "2019-02-01T21:30:15Z")

</div>

The client (and designer) are built in Jython, a Java-based implementation of Python. This means you can access the Java-based GUI of the client. Doing this, you have more (unsupported by IA) control over the client and how it reacts. See [this](https://docs.oracle.com/javase/tutorial/uiswing/misc/keybinding.html) page for more information on input/action maps and how to work with them.

I explored this input map stuff, you can take a look here. In this example, it prints out a lot of stuff and then when it finds the entry in an inputmap that is just for pressing F10, it removes it. What you’d want to do is add an action to that component’s action map, and add that action’s key to the input map for F10 (where in my script, I just have a blank string). Hope this helps.

```auto
	from javax.swing import SwingUtilities as su
	from javax.swing import JComponent
	
	
	ancWin = su.getWindowAncestor(self).getComponent(0)
		
	inMap = ancWin.getInputMap()
	
	consts = [['ancestor of focused', JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT],
				['whenfocused', JComponent.WHEN_FOCUSED],
				['when in focused window', JComponent.WHEN_IN_FOCUSED_WINDOW]
				]
	
	def recMap(c, i = 0):
		selfMap = {}
		try:
			for x in consts:
				selfMap[x[0]] = c.getInputMap(x[1])
		except:
			selfMap = None
		
		
		for k, v in selfMap.items():
			if v != None:
				if v.allKeys() is not None:
					print c
					print ' %s:' % k
					for imk in v.allKeys():
						print ' %s: %s' % (imk, v.get(imk))
						if str(imk) == 'pressed F10':
							v.put(imk, "") ####Here, replace the blank quotes with the key to a new entry in component c's actionmap
		
		try:
			if i < 5:	#prevent too much recursion
				for c in c.getComponents():
					recMap(c, i + 1)
		except:
			pass
			
	recMap(ancWin)

```

Edit: I put this on a button for testing purposes. but I think you might put it in one of your ‘open on startup’ visionWindowOpened scripts.

---

<div class="post-metadata">

**Author:** ![kunal.ghule](https://avatars.discourse-cdn.com/v4/letter/k/5daacb/32.png) [@kunal.ghule](https://forum.inductiveautomation.com/u/kunal.ghule)\
**Post date:** [February 4, 2019, 4:37pm UTC](https://forum.inductiveautomation.com/t/client-keystroke-script/22289/7 "2019-02-04T16:37:20Z")

</div>

Thank you Micheal, appreciate it.

---

<div class="post-metadata">

**Author:** ![kartik.i](https://avatars.discourse-cdn.com/v4/letter/k/e9c0ed/32.png) [@kartik.i](https://forum.inductiveautomation.com/u/kartik.i)\
**Post date:** [February 19, 2019, 5:50am UTC](https://forum.inductiveautomation.com/t/client-keystroke-script/22289/8 "2019-02-19T05:50:20Z")

</div>

Hi mrogers,

I am facing issue if we are using your script for F10 keystroke.

I have attached error message for your reference

Thanks,  
Kartik I  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/814205feb1e0c2675e549c775e6a401c6a0b9273.png)

---

<div class="post-metadata">

**Author:** ![mrogers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mrogers/32/4110_2.png) [@mrogers](https://forum.inductiveautomation.com/u/mrogers)\
**Post date:** [February 19, 2019, 4:22pm UTC](https://forum.inductiveautomation.com/t/client-keystroke-script/22289/9 "2019-02-19T16:22:33Z")

</div>

Depending on where you’re running it, that ‘self’ may need to change. All it really needs to be is some kind of component in an open window. If this is to be run every time the client is opened, I’d suggest putting this on the visionWindowOpened function on one of the windows you have set to open on startup.
