How to prevent conflict with other interface keys

72 views
asked Jan 8 in GUI Development by Tonny

Hello Paul,

     In this document.    https://doc.embedded-wizard.de/mosaic_core?v=9.30#KeyCode  

   The Core::KeyCode.CursorKeys only included the Left,Right,Up,Down.

  

But now,I want to add a key(Enter),Is there a way to add a key?Instead of using  Core::KeyCode.AnyKey.

Maybe i need to redenfine a new item?Because I need to use keys on other interfaces .So i want to prevent conflict with other interface keys .

Best regards,

Tonny

 

1 Answer

0 votes
answered Jan 8 by Paul Banach
 
Best answer

Hello Tonny,

the redefinition of the Core::KeyCode enumeration is not possible. The set of key codes is fixed predefined. Instead I would add 2 separate Key Press Handlers to the GUI component. The first handler could be configured to react to CursorKeys. The second handler should be configured to handle the Enter key. This is the most typical application case.

Doing this has also the nice advantage of the possibility to implement separate slot methods for the respective Key Press Handlers. For example, you could implement a slot method named onPressCursorKey and connect it to the first handler. Then you implement the method OnPressEnterKey and connect it to the second handler. Within the methods you don't need to distinguish whether the user has pressed a cursor or Enter key. In practice, you can even have individual Key Press Handler for each key e.g. Left, Right, Up and Down. This would be in total 5 handlers. There is no limitation regarding the number of handlers used within a GUI component.

The approach of having multiple Key Press Handlers does not enforce your component to have individual slot methods for each handler. You can connect all handlers to one and the same slot method. Then, however, you have to test in the slot method which handler was the sender. Accordingly you perform the associated code section.

Other also fully legitim approach is to have a single Key Press Handler configured with AnyKey as filter condition. Within the associated slot method you test whether the key code is the interesting one and if this is not the case you instruct the handler to reject this event.

I hope one of the options helps you further.

Best regards

Paul banach

commented Jan 9 by Tonny

Hello Paul,

      Sorry,I don't understand a little.

    First, I have add the slot method,The onKeyPressSlot slot method code is :

var Core::View      view      = null;
var Core::Direction direction = Core::Direction.None;

// Depending on the pressed key, determine the direction to look
// for the new view to select.
switch ( keyHandlers.Code)
{
  case Core::KeyCode.Up    : direction = Core::Direction.Top;
  case Core::KeyCode.Down  : direction = Core::Direction.Bottom;
  case Core::KeyCode.Left  : direction = Core::Direction.Left;
  case Core::KeyCode.Right : direction = Core::Direction.Right;
  default :;
}

// Search the component for a view relative to the currently selected view,
// which is determined by the property 'Focus'. Ignore all views, which are
// invisible or not allowed to be selected.
view = FindViewInDirection( Focus, direction, 
                                   Core::ViewState[ Enabled, Visible, Focusable ]);

// If a view has been found, select it now. If no view was found, the current
// selection remains unchanged.
if ( view != null )
  Focus = view;

Is I missing code on OnKeyEnterSlot method?

Second:How to Choose in the HorizontalSlider .

My purpose is Select one and slide 

Only use up,down,left,right to select,and use Enter to lock and slide,If I don't lock then pressing the left and right keys will move to the next  HorizontalSlider.

Thank you very much!

Best regards,

Tonny

commented Jan 9 by Paul Banach

Hello Tonny,

what do you mean with 'Is I missing code on OnKeyEnterSlot method?'. Have you connected the method OnKeyEnterSlot to the handler KeyHandlerEnter? and have you configured the handler to react to the Enter key? If yes, the slot method should be invoked when the user presses the Enter key. Is this not the case? Do you have an error?

The code within the OnKeyPressSlot should navigate between the Sliders. Does it work? Once you have a Slider selected you can change its current value by using the keys + and - (plus and minus). If you want the Slider to react to other keys, you can create your own Slider configuration object and specify there the desired key codes

The possibility to 'lock' the Slider with a key e.g. Enter is not supported by the default widgets. If you want a Slider with such particular behavior you will need to implement your own Slider component. To simplify this implementation create the Slider from the provided component templates.

Does it help you?

Best regards

Paul Banach

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...