Respones to keyboard input?

I’m not familiar with the win32 programming stuff, but I realy want to know if it’s
possible to have the cocos2d-win32 respones to the keyboard input (such as the
arrow keys) like the win32 app does so thar I cound use it to simulate the
accelerometer(that could be cool_)

Yes, it’s a part of 0.99.5-x-0.7.2. Keyboard input of both win32 & mac will be supported.

Have an example?

I wrote a demo several months ago and it’s base on an older version, you can find the demos and tutorial in my site:

http://www.supersuraccoon-cocos2d.com/2011/04/25/cocos2d-x-win32-solution-of-using-the-keyboard-to-simulate-accelerometer/

Hope it helps :slight_smile:

Thanks a lot, Mr.SuRaccoon :slight_smile:

Would it be possible for anyone with a better understanding of the older versions of Cocos2d-x to update the project for 1.0+? Or a guide on exactly how to update it. I started using Cocos2d a while back, but started to use Cocos2d-x in the later .9 versions.

Things were changed quite a bit it seems, and the code has tons of errors in the way it works. I’m sure it would be valuable for multiple people, and could be updated and uploaded to the extensions repo if there is one.

I appreciate any help, and look forward to hearing back! Thank you,

Bryan Taylor

I have a workaround for 1.0.1-x-0.12.0 but since in 0.13.0 the view id was removed the tunneling in to the layer has to be performed in another way.
I modified CCEGLView_win32.cpp (under cocos2dx\platform\win32) the method CCEGLView::WindowProc to catch (for example) a key down event i added the following code:

case WM_KEYDOWN: { //THIS IS THE NEW CODE (START) CCTouch* keyIDContainer = new CCTouch(); keyIDContainer->SetTouchInfo(wParam,0,0); CCSet* newSet = new CCSet(); newSet->addObject(keyIDContainer); m_pDelegate->touchesBegan(newSet, NULL); //THIS IS THE NEW CODE (END) if (wParam == VK_F1 || wParam == VK_F2) { if (GetKeyState(VK_LSHIFT) < 0 || GetKeyState(VK_RSHIFT) < 0 || GetKeyState(VK_SHIFT) < 0) CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(wParam == VK_F1 ? kTypeBackClicked : kTypeMenuClicked); } if ( m_lpfnAccelerometerKeyHook!=NULL ) { (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam ); } } break;

Afterwards i recompiled the libcocos2d project. I added my version of the touch dispatcher (catches arrow key events).

In you layer you just enable touch events via this->setIsTouchEnabled(true);
And implement the following method to catch Key events:

`void HelloWorld::ccTouchesBegan(CCSet* touches, CCEvent* event)
{
CCTouch* keyDataWrapper = (CCTouch*)touches->anyObject();
if(keyDataWrapper->view() == 37){
//Move Left
} else if(keyDataWrapper->view() == 39) {
//Move Right
} else if(keyDataWrapper->view() == 38){
//Move Uo
} else {
//Touch
}
}

void HelloWorld::ccTouchesEnded(CCSet* touches, CCEvent* event)
{
CCTouch* keyDataWrapper = (CCTouch*)touches->anyObject();
if(keyDataWrapper->view() == 37){
//Move Left
} else if(keyDataWrapper->view() == 39) {
//Move Right
} else if(keyDataWrapper->view() == 38){
//Move Uo
} else {
//Touch
}
}`