mirror of https://github.com/axmolengine/axmol.git
47 lines
1003 B
C++
47 lines
1003 B
C++
#include "KeyboardTest.h"
|
|
|
|
#ifdef CC_KEYBOARD_SUPPORT
|
|
|
|
KeyboardTest::KeyboardTest()
|
|
{
|
|
auto s = Director::getInstance()->getWinSize();
|
|
auto label = LabelTTF::create("Keyboard Test", "Arial", 28);
|
|
addChild(label, 0);
|
|
label->setPosition( Point(s.width/2, s.height-50) );
|
|
|
|
setKeyboardEnabled(true);
|
|
|
|
// create a label to display the tip string
|
|
_label = LabelTTF::create("Please press any key and see console log...", "Arial", 22);
|
|
_label->setPosition(Point(s.width / 2, s.height / 2));
|
|
addChild(_label, 0);
|
|
|
|
_label->retain();
|
|
}
|
|
|
|
KeyboardTest::~KeyboardTest()
|
|
{
|
|
_label->release();
|
|
}
|
|
|
|
void KeyboardTest::keyPressed(int keyCode)
|
|
{
|
|
log("Key with keycode %d pressed", keyCode);
|
|
}
|
|
|
|
void KeyboardTest::keyReleased(int keyCode)
|
|
{
|
|
log("Key with keycode %d released", keyCode);
|
|
}
|
|
|
|
void KeyboardTestScene::runThisTest()
|
|
{
|
|
auto layer = new KeyboardTest();
|
|
addChild(layer);
|
|
|
|
Director::getInstance()->replaceScene(this);
|
|
layer->release();
|
|
}
|
|
|
|
#endif
|