Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

New Contributor
Posts: 4
Registered: ‎02-08-2013
My Device: Blackberry 10 and playBook
My Carrier: Simulator Blackberry 10 and playBook

Re: how to capture keyboard input in cascades?

I tried to set up the KeyListerner with my sumulator " OS :".


To be sure I'm not doing any mistake I did 2 test, one is tu catch LongPressHandler and the seconde catch KeyListener. I tested with LongPressHandler because that use the same patern, so in theory I need just to change the methods names and params to make it works.


here my hpp file :


class KeyGrill: public bb::cascades::Container {
KeyGrill(bb::cascades::Container *container);

public slots:
void onKeyEventHandler(bb::cascades::KeyEvent *key);
void onKeyPressedHandler(bb::cascades::KeyEvent *key);
void onKeyReleasedHandler(bb::cascades::KeyEvent *key);
void onLongPressedHandler(bb::cascades::LongPressEvent *event);

 and new my cpp:


KeyGrill::KeyGrill(bb::cascades::Container *container) : Container(container) {

KeyListener* myKeyListener = KeyListener::create().onKeyEvent(this, SLOT(onKeyEventHandler(bb::cascades::KeyEvent *)))
														   .onKeyPressed(this, SLOT(onKeyPressedHandler(bb::cascades::KeyEvent *)))
														   .onKeyReleased(this, SLOT(onKeyReleasedHandler(bb::cascades::KeyEvent *)));

LongPressHandler *pLongPressHandler = LongPressHandler::create().onLongPressed(this, SLOT(onLongPressedHandler(bb::cascades::LongPressEvent*)));



void KeyGrill::onKeyReleasedHandler(bb::cascades::KeyEvent *key){
	qDebug() << "key :" << key->key();

void KeyGrill::onKeyEventHandler(bb::cascades::KeyEvent *key) {
	qDebug() << "key :" << key->key();

void KeyGrill::onKeyPressedHandler(bb::cascades::KeyEvent *key) {
	qDebug() << "key :" << key->key();

void KeyGrill::onLongPressedHandler(bb::cascades::LongPressEvent *event) {
	qDebug() << "long press";

 so with the simulator I can catch the "long press" but not the keyboard even with the PC's keyboard or virtual's keyboard (simulator).

Someone can explaine why that issue ? And don't tell me it because I'm using a custome Container, "LongPressHandler" is working!!!