Adding a newly made method to a keyListener

Questions and answers on developing, deploying and using plugins and JavaBeans

Adding a newly made method to a keyListener

Postby mees » Mon Apr 20, 2020 3:16 pm

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:

Code: Select all
         /** @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
Code: Select all
         /** @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
Code: Select all
         plugins.keyListener.addKeyListener('keyListener_' + elementName, method.getUUID(), true);
         plugins.keyListener.addKeyListener('keyListener_' + elementName, method.getName(), true);


But both to no avail.
mees
 
Posts: 6
Joined: Fri Dec 28, 2018 3:53 pm

Re: Adding a newly made method to a keyListener

Postby mboegem » Mon Apr 20, 2020 5:14 pm

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:
Code: Select all
plugins.keyListener.addKeyListener('keyListener_' + elementName, forms.myForm[method.getName()], true);


Hope that helps.
_____________________
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance SAN Developer

Image
User avatar
mboegem
 
Posts: 1573
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: Adding a newly made method to a keyListener

Postby mees » Tue Apr 21, 2020 8:23 am

That did the trick, thank you very much Marc!
mees
 
Posts: 6
Joined: Fri Dec 28, 2018 3:53 pm


Return to Plugins and Beans

Who is online

Users browsing this forum: No registered users and 5 guests