Welcome!

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

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

Re: how to capture keyboard input in cascades?

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

 

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 {
 
Q_OBJECT
public:
KeyGrill(bb::cascades::Container *container);
~KeyGrill();

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*)));

(static_cast<Container*>(this->parent()))->addKeyListener(myKeyListener);
(static_cast<Container*>(this->parent()))->addGestureHandler(pLongPressHandler);

}

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!!!