Log in

View Full Version : Capturing Keypresses



Brenn
November 22nd, 2008, 13:05
Is there any way to capture a keypress inside a control?

Basically what I'm trying to accomplish is this: I have a windowlist for data entry. If I'm on the last control on a particular item and the user presses tab or enter I want to automatically create a new item in the windowlist and shift the focus to the first control of the newly created windowlist item. I think I could work around this using <tabtarget> and code in the first and last controls of the windowlist entry, but capturing the keypress is the proper way to do it so I'm asking.

Foen
November 23rd, 2008, 06:16
Key press capture is available to some extent in anything inherited from textbasecontrol (the stringcontrol and stringfield controls) and is used in the default d20 ruleset for inventory entries. The events are onTab (which catches forward and backward tabs), onEnter, onDeleteDown (DEL, I think), onDeleteUp (backspace) and onChar. The arrow keys are captured by the onNavigate... event handlers.

Unfortunately this functionality isn't available for number controls or fields :( and is one of the things on my Christmas wish list.

Foen

Brenn
November 23rd, 2008, 11:22
Thanks, in my situation that will work well, but not having the same with Numberfields is irritating and worth remembering.

Moon Wizard
November 25th, 2008, 07:55
Try checking out the textlistitemvalue template in the charsheet_templates.xml included with the default d20 ruleset.

It does something very similar to what you are looking at.

Cheers,
JPG