Adding a newly made method to a keyListener

Hi all,

I am currently making a function that creates keylisteners and callbacks on the fly, and adds them to an element. I’ve got it all working, except for one thing: I cannot get the addKeyListener method to recognize my new method correctly. The code to do so seems to be quite simple:

			/** @type {JSMethod} */
			var method = solutionForm.newMethod(methodCode);
			plugins.keyListener.addKeyListener('keyListener_' + elementName, method, true);

The first call creates a function called onKeyTxtTest for me. This works properly. It’s the second line that doesn’t function propertly. If I use the code

			/** @type {JSMethod} */
			var method = solutionForm.newMethod(splitCode.join('\n'));
			plugins.keyListener.addKeyListener('keyListener_' + elementName, onKeyTxtTest, true);

everything works as intended. So how do i get the addKeyListener-function to recognize my method? I tried

			plugins.keyListener.addKeyListener('keyListener_' + elementName, method.getUUID(), true);
			plugins.keyListener.addKeyListener('keyListener_' + elementName, method.getName(), true);

But both to no avail.

Hi Mees,

the addKeyListener function expects the callbackFunction as a reference to the function.

So if you created the method on form ‘myForm’ this should work:

plugins.keyListener.addKeyListener('keyListener_' + elementName, forms.myForm[method.getName()], true);

Hope that helps.

That did the trick, thank you very much Marc!