主题:[讨论]求高手指导,程序运行后onkeydown不起作用,键盘控制不了
用vc++6.0编程,实现对移动小车的键盘控制
void CCGViewView::OnKeycontrol()
{
BootMode = BootMode_Key; //键盘控制
process_state = ROBOT_STOP;
}
void CCGViewView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(BootMode == BootMode_Key) //用键盘控制
{
if(nChar == VK_UP)
{
process_state = ROBOT_DIRECT_MOVE;
}
else if(nChar == VK_DOWN)
{
process_state = ROBOT_INDIRECT_MOVE;
}
else if(nChar == VK_LEFT)
{
process_state = ROBOT_SWIRL_MOVE;
}
else if(nChar== VK_RIGHT)
{
process_state = ROBOT_INSWIRL_MOVE;
}
}
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CCGViewView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(BootMode == BootMode_Key) //用键盘控制
{
if(nChar == VK_UP || nChar ==VK_DOWN || nChar == VK_LEFT || nChar == VK_RIGHT)
process_state = ROBOT_STOP;
}
CView::OnKeyUp(nChar, nRepCnt, nFlags);
}
BOOL CCGViewView::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if( pMsg-> message==WM_KEYDOWN)
{
SendMessage(WM_KEYDOWN,pMsg-> wParam,0);
}
if(pMsg->message == WM_KEYUP)
{
SendMessage(WM_KEYUP,pMsg->wParam,0);
}
return CView::PreTranslateMessage(pMsg);
}
运行之后,按下键盘,小车不动,哪位大侠指导问题出在哪里呢?