This Question is Answered

15 "helpful" answers available (3 pts)
5 Replies Last post: Jul 2, 2008 12:00 AM by markecho

How to change one Keyboard event to the other Keyboard event?

Jul 1, 2008 3:20 AM

Click to view markecho's profile Level 2 markecho 32 posts since
Oct 17, 2007

Hi.

I have a problem about keyboard event.

for instance, on the keyboard , I strike the "m" + "ctrl" + "shift" key at one time, then I want to get the effect that looks like I strike "shift" + "tab",

that means the focus in the current controller moves to the last controller.

Is the "KeyPress" event useful? and how could I do?

Thank you for your help :-)

Click to view friedger's profile MVP friedger 103 posts since
Jan 13, 2008
1. Re: How to change one Keyboard event to the other Keyboard event? Jul 1, 2008 4:16 AM

There is the method {ActiveTraversalContainer.traverse forward?:bool = true}:bool that moves the focus. So you don't have to create new Events.

Friedger

Click to view carl's profile Curl carl 62 posts since
Oct 17, 2007
2. Re: How to change one Keyboard event to the other Keyboard event? Jul 1, 2008 6:00 PM
Traversal is a good option if you're looking for tab-like navigation.

If you're looking for quick keyboard access to controls, you could also set the "mnemonic" local option to provide alt+(key) shortcuts.
Click to view markecho's profile Level 2 markecho 32 posts since
Oct 17, 2007
3. Re: How to change one Keyboard event to the other Keyboard event? Jul 1, 2008 10:27 PM
in response to: friedger

thank you,Friedger, Carl

And could you give me an example of using method ActiveTraversalContainer.traverse?

for example, I have a TextField control ,a CommandButton A and a CommandButton B,

At beginning, the focus is in the TextField,

after I click B, then focus is on the A.

Thanks a lot.

Click to view carl's profile Curl carl 62 posts since
Oct 17, 2007
4. Re: How to change one Keyboard event to the other Keyboard event? Jul 1, 2008 10:56 PM
in response to: markecho
Here's an example with both a click handler that traverses and a key handler that jumps.

Click on cb2 (or press space when it has focus) and cb1 will become active. This happens by asking cb2 what active traversal container it is in, then asking that container to make the "previous" traversor active, just like when pressing shift-tab. cb2 doesn't know who is previous, it is asking the container to do the work and pick someone. The way it's written here, this will happen regardless of whether it's cb2 that has the focus, so if you uncomment the takes-focus? line, clicking on the button will actually toggle the active control between the two others, since cb2 will opt not to take part in its container's traversal.

Press ctrl+shift+m at cb1 when it has focus and tf will become active. This happens by directly asking the TextField to become the active control for its container.

Note the "after 0s" which politely queues the navigation rather than immediately forcing it.

{def tf = {TextField}}
 
{def cb1 =
    {CommandButton
        {on e:KeyPress at cb:CommandButton do
            {if not e.consumed? and
                {e.modifiers-match? shift? = true, ctrl? = true} and
                e.value == 'M' or e.value == 'm'
             then
                {after 0s do
                    {tf.become-active}
                }
                {e.consume}
            }
        }
    }
}
 
{def cb2 =
    {CommandButton
||--        takes-focus? = false,
        {on Action at cb:CommandButton do
            {after 0s do
                {if-non-null atc = cb.active-traversal-container then
                    {atc.traverse forward? = false}
                }
            }
        }
    }
}
 
{spaced-vbox tf, cb1, cb2}
Click to view markecho's profile Level 2 markecho 32 posts since
Oct 17, 2007
5. Re: How to change one Keyboard event to the other Keyboard event? Jul 2, 2008 12:00 AM
in response to: carl

thank you, carl, your answer is a great help for me. :-)