Touch-sensitive keyboard input 10.3

The keyboard on the BlackBerry Passport smartphone is touch sensitive, meaning that it can recognize touch events and gestures in addition to key presses. For most Cascades apps, you don't have to do anything to take advantage of the the touch-sensitive keyboard. If your app includes a ListView or a ScrollView , the user can swipe the keyboard to scroll through these views.

However, if your app has a complex layout or more than one "scrollable" view in it, scrolling may not work as expected. In these cases, you must set the main scrollable area manually. Here's how to set a ListView as the main scrollable area.

A .gif that shows how to scroll a screen using the touch-sensitive keyboard.
ListView {
    scrollRole: ScrollRole.Main
ListView* listview = ListView::create().scrollRole(ScrollRole::Main);

Not applicable

If you want more control, you can capture and handle touch-sensitive keyboard events manually.

Touch-sensitive keyboard events

To capture touch-sensitive keyboard events you can use either the TouchkeyboardHandler in Cascades or the SCREEN_EVENT_MTOUCH_EVENT session from the Screen Graphics Subsystem.

In Cascades, you can create a TouchKeyboardHandler and attach it to any VisualNode in the scene using the eventHandlers property. While that node has focus and the user is swiping the touch-sensitive keyboard, touch events are delivered through the handler's touch() signal. Each TouchKeyboardEvent contains information such as the position of the touch and the touch type (down, move, up, or cancel).

To receive touch-sensitive keyboard events using C, create a SCREEN_EVENT_MTOUCH_TOUCH session. To retrieve information from the events, use the screen_get_session_property_*() functions. Some properties that may be of interest are:


Alternatively, you can use the Input Events library to retrieve information from a touch event. You can use screen_get_mtouch_event() to retrieve information from an mtouch_event structure that was populated as the result of a SCREEN_EVENT_MTOUCH_EVENT event.

import bb.cascades 1.3

Page {
    Container {
        id: theContainer
        focusPolicy: FocusPolicy.Touch
        // Requests focus for the container so that events can start
        // being delivered.
        onCreationCompleted: { 
        eventHandlers: [
            TouchKeyboardHandler {
                onTouch: {
                    // Prints out the type of event that occurs
                    console.log("TouchKeyboard: " + event.touchType) 

Coming soon

To receive touch events from all devices, create a SCREEN_EVENT_MTOUCH_TOUCH session that's not bound to any window, also known as a windowless session:

screen_session_t session;
screen_create_session_type(&session, context, SCREEN_EVENT_MTOUCH_TOUCH);

Alternatively, if you want your app to receive data only from devices that are on-screen, you can create the session and bind it to a window as follows:

screen_session_t session;
screen_create_session_type(&session, context, SCREEN_EVENT_MTOUCH_TOUCH);
screen_set_session_property_pv(session, SCREEN_PROPERTY_WINDOW, (void **)&window);

Last modified: 2015-05-07

Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus