There are several ways that you use sessions to handle text input in your app. This section provides an overview of those methods.
Use the following code to create a session when entering a text field:
screen_session_t session;
screen_create_session_type(&session, context, SCREEN_EVENT_KEYBOARD);
screen_set_session_property_pv(session, SCREEN_PROPERTY_WINDOW,
Similarly, destroy the session when a click is detected outside of the text field or an event is received indicating that the window has lost input focus.
Use the following code to destroy a session when leaving a text field:
screen_destroy_session(session);
Alternatively, you can create an input region that matches the text field:
screen_session_t session;
screen_create_session_type(&session, context, SCREEN_EVENT_KEYBOARD);
screen_set_property_pv(session, SCREEN_PROPERTY_WINDOW, (void **)&window);
screen_set_property_iv(session, SCREEN_PROPERTY_POSITION, pos);
screen_set_property_iv(session, SCREEN_PROPERTY_SIZE, size);
Rather than creating and destroying sessions as fields gain and lose focus, you may instead want to create a session and keep it active at all times, changing the session's mode upon entering and leaving text fields.
Create a session the same way as when dynamically creating your sessions:
screen_session_t session;
screen_create_session_type(&session, context, SCREEN_EVENT_KEYBOARD);
screen_set_session_property_pv(session, SCREEN_PROPERTY_WINDOW,
Upon entering a text field, set the input mode to text:
int mode = SCREEN_INPUT_MODE_TEXT_ENTRY;
screen_set_session_property_iv(session, SCREEN_PROPERTY_MODE, &mode);
Upon leaving a text field, set the input mode to navigation:
int mode = SCREEN_INPUT_MODE_NAVIGATION;
screen_set_session_property_iv(session, SCREEN_PROPERTY_MODE, &mode);