i should add onKeyPress event on Power Table component. To do this, from what i understand, i need to add a Listener on the Key side.
I tried to do it using some code inside initialize extension function but it the event doesn't fired out:
from java.awt.event import KeyListener #KeyAdapter
#class KA(KeyAdapter):
class KL(KeyListener):
def keyPressed(ev):
print ev.getKeyCode(), ev.getKeyChar()
c = KL() #KA()
self.addKeyListener(c)
Neither the KeyListener nor the KeyAdapter work when a key is pressed.
Does anyone know how to do this?
PS: I saw in the forum (here) that someone has already succeeded using different functions.. but i simply want to print the .getKeyChar() and the .getKeyCode() of the key just pressed.
I like to add keyboard shortcuts to power tables in some cases. I do this by adding the following to the 'initialize' extension function of the table.
In the example below deleteRow is a custom method that I added to the table. I always use a custom method so that I can trigger the same action with either a key press or a right click event.
The script will not work in the desginer though without a couple of extra steps. To verify it works in the designer you will need to start preview mode with the window closed. Open the window while still in preview mode. That will cause the initialize script to run and the keyboard shortcut will work as long as the table has focus.
from javax.swing import AbstractAction, JComponent, KeyStroke
class MyAction(AbstractAction):
def actionPerformed(self, ev):
#print "onKeyPressed!"
cmp = ref.parent.getComponent('Del')
if cmp.componentEnabled:
cmp.delTags()
a = MyAction()
k = KeyStroke.getKeyStroke("released DELETE")
self.registerKeyboardAction(a, k, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
What i wanted to do now was to also add additional listener instance that would print to the Ignition console the keys i press on the keyboard when i have one or more power table's cells focused.
Why would we need text arbitrarily printed to the console? Is there a bigger picture problem that we are trying to solve? Real time text validation perhaps?