语言

Menu
Sites
Language
How to make app respond to key press?

Hi,

I am developing an app for TV. I want the app to disappear from the TV screen when back key of the remote control is pressed. 

How can it be done?

Regards,

Nikhil

响应

1 回复
Shuhrat Dehkanov

I think evas_object_event_callback_add() is what you are looking for:

 - use EVAS_CALLBACK_KEY_DOWN as Evas_Callback_Type,
 - in the callback function check the keyname from event_info (the 4th parameter), and
 - call elm_exit() if it is a back key to exit the main loop.

Something like this:

static void _on_key_down(void *some_data, Evas *e, Evas_Object *obj, void *event_info)
{
    Evas_Event_Key_Down *ev;
    ev = (Evas_Event_Key_Down *)event_info;
    if (ev && !strcmp(ev->keyname, KEY_BACK_REMOTE))
        elm_exit();
}

// ...

evas_object_event_callback_add(my_Evas_Obj, EVAS_CALLBACK_KEY_DOWN, _on_key_down, some_data);

I could not find exact definition of KEY_BACK_REMOTE in official docs, but you can print keyname to see what exactly is passed to your app when back key of the remote control is pressed and replace it with that value (or redefine it).

Hope this helps.