2013-05-31 20:29:32 +08:00
|
|
|
#include "KeyboardTest.h"
|
|
|
|
|
2013-06-12 09:20:18 +08:00
|
|
|
#ifdef KEYBOARD_SUPPORT
|
|
|
|
|
2013-05-31 20:29:32 +08:00
|
|
|
KeyboardTest::KeyboardTest()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Size s = Director::sharedDirector()->getWinSize();
|
|
|
|
LabelTTF* label = LabelTTF::create("Keyboard Test", "Arial", 28);
|
2013-05-31 20:29:32 +08:00
|
|
|
addChild(label, 0);
|
|
|
|
label->setPosition( ccp(s.width/2, s.height-50) );
|
|
|
|
|
|
|
|
setKeyboardEnabled(true);
|
|
|
|
|
|
|
|
// create a label to display the tip string
|
2013-06-20 14:17:10 +08:00
|
|
|
_label = LabelTTF::create("Please press any key and see console log...", "Arial", 22);
|
2013-06-15 14:03:30 +08:00
|
|
|
_label->setPosition(ccp(s.width / 2, s.height / 2));
|
|
|
|
addChild(_label, 0);
|
2013-05-31 20:29:32 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_label->retain();
|
2013-05-31 20:29:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
KeyboardTest::~KeyboardTest()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_label->release();
|
2013-05-31 20:29:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void KeyboardTest::keyPressed(int keyCode)
|
|
|
|
{
|
|
|
|
CCLog("Key with keycode %d pressed", keyCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeyboardTest::keyReleased(int keyCode)
|
|
|
|
{
|
|
|
|
CCLog("Key with keycode %d released", keyCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeyboardTestScene::runThisTest()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* pLayer = new KeyboardTest();
|
2013-05-31 20:29:32 +08:00
|
|
|
addChild(pLayer);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Director::sharedDirector()->replaceScene(this);
|
2013-05-31 20:29:32 +08:00
|
|
|
pLayer->release();
|
|
|
|
}
|
2013-06-12 09:20:18 +08:00
|
|
|
|
|
|
|
#endif
|