cocos2d-x给win32增加按键响应

在CCLayer.h中
添加成员方法

virtual void processWin32KeyPress(UINT message, WPARAM wParam, LPARAM lParam) {}

CCEGLView_win32.h中添加
私有成员变量

CCLayer *m_pLayWin32Key;

并增加函数

void SetWin32KeyLayer(CCLayer *pLayer)
{
	m_pLayWin32Key = pLayer;
}

同时,在CCEGLView::WindowProc函数中,增加这一行

LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
	if(NULL != m_pLayWin32Key)
	{
		m_pLayWin32Key->processWin32KeyPress(message, wParam, lParam);
	}
	......(原有的,略)
}

改造CCEGLView构造函数

CCEGLView::CCEGLView()
: m_bCaptured(false)
, m_bOrientationReverted(false)
, m_bOrientationInitVertical(false)
, m_pDelegate(NULL)
, m_pEGL(NULL)
,m_pLayWin32Key(NULL)	//增加这一行
, m_hWnd(NULL)
, m_eInitOrientation(CCDeviceOrientationPortrait)
, m_fScreenScaleFactor(1.0f)
, m_lpfnAccelerometerKeyHook(NULL)
{
    m_pTouch    = new CCTouch;
    m_pSet      = new CCSet;
    m_tSizeInPoints.cx = m_tSizeInPoints.cy = 0;
    SetRectEmpty(&m_rcViewPort);
}

使用方法
HelloWorld(.h文件)中增加成员函数

virtual void processWin32KeyPress(UINT message, WPARAM wParam, LPARAM lParam);

在.ccp中的构造函数中,增加

void HelloWorld::processWin32KeyPress(UINT message, WPARAM wParam, LPARAM lParam)
{
	//此处与其他win32程序类似
}

同时增加

CCDirector::sharedDirector()->getOpenGLView()->SetWin32KeyLayer(this);	

否则没响应.

抛砖引玉,希望各位指点批评。

?用!{:soso__16984349925490629196_1:}

太好了,正在找这个问题的答案呢,高手啊高手{:soso_e142:}

能不能给个响应鼠标移动的方法,现在的移动只能在鼠标点击后才能捕获,就是说是响应的触摸板的移动,而不是windows里的鼠标移动。