How to write a method

For questions and postings not covered by the other forums
sit
Posts: 13
Joined: Mon Sep 29, 2014 6:53 pm

How to write a method

Postby sit » Wed Oct 22, 2014 1:20 pm

Hi
Does anyone know how I would write a method that allows access to another form by way of keyboard instruction ? Much like the way a user types ctrl, alt, delete to access the task manager on a pc. There is no forward prompting this instruction only a user who is familiar with the database would know to do this?

User avatar
BeeJay
Posts: 312
Joined: Tue Jun 30, 2009 2:42 pm
Location: Christchurch, NZ

Re: How to write a method

Postby BeeJay » Wed Oct 22, 2014 1:53 pm

Check out the Form::keyUp event. You'd implement this event method on the 'Form' from which you want to do the 'secret key sequence' to open another form. You can use the 'shift' parameter to determine if Ctrl, Shift or Alt keys were also pressed at the same time.

Note: For performance reasons, in a production application if you had the need to respond to certain keystrokes you should also utilise the Form::registerFormKeys method when implementing any of the keyDown, keyUp or keyPress events at the form level. This will help ensure that every time a user types into a field on that form it doesn't do a round-trip to the AppServer for every keystroke. This would be particularly noticeable on a slower network connection and could annoy people who can type faster than the time it takes to complete a round-trip. :)

Cheers,
BeeJay.

sit
Posts: 13
Joined: Mon Sep 29, 2014 6:53 pm

Re: How to write a method

Postby sit » Wed Oct 22, 2014 5:31 pm

Could you give me some idea of how to actually write this piece of code ?

User avatar
BeeJay
Posts: 312
Joined: Tue Jun 30, 2009 2:42 pm
Location: Christchurch, NZ

Re: How to write a method

Postby BeeJay » Wed Oct 22, 2014 8:08 pm

Step 1 - Select your form in the class browser, then in the middle pane click on the <form> entry, it will be red and at the top of the middle properties pane. The right hand pane will then show you the available event methods for a form. Select the keyUp event from the methods pane so you can implement code in that method.

Step 2 - Put in a write statement to write out the value of keyCode, run your app and then press the letter key you want to use as part of your 'sequence' to find out the keyCode for the desired key.

Step 3 - Implement some logic on the 'shift' parameter to work out which of the modifier keys (Shift, Ctrl, Alt) are also pressed and if they've done the correct combination of Ctrl/Alt/Shift + key, then you would create and show your other form.

Hints:

1. There are already some Jade constants like J_key_ ... which may be useful for determining if they pressed the 'letter' key that forms part of the secret sequence.

2. You'll want to look at the bitAnd logic as per the Jade Help for keyUp event for determining which of the modifier keys were pressed.

http://jade.co.nz/docs/jade/Default.htm ... /keyup.htm

Note: I could show you code that does this, but you'll learn more from working it out yourself and I don't want to step on your lecturer's toes. However, if you've tried the code and are still having issues with it not working, paste in your code and I'll see if I can point you in the right direction. :)

Cheers,
BeeJay.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 10 guests

cron