Client Keystroke Script

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.

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?

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.

You will have to use a client startup script and manipulate the ActionMap and InputMap in the client yourself if you want to “override” the F10 behavior.

1 Like

Hello Paul,

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

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 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.

	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.

5 Likes

Thank you Micheal, appreciate it.

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

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.