Touches using keyboard

Hello Guys, Lately I’ve been experimenting with Keyboard using GetKeyState inside of the Update method and it’s showing good results, however it’s hard to control the flow of program inside the Update method. Currently I’m looking for a way to use GetKeyState to generate a touch or a dispatcher triggering that a ccTouchBegan occurred do you guys have any idea how to do it?

Example

//The button
bool HelloWorld::ccTouchBegan(CCTouch* touch, CCEvent* event)
{
    location = this->convertTouchToNodeSpace(touch);
    if (CCRect::CCRectContainsPoint(leftButton.BoundingBox(),location))
    {
               make the sprite move Left....
    }
}

The init method that will generate a touch

void HelloWorld::update(ccTime dt)
{   
    if (GetKeyState(VK_LEFT) & 0x8000)
        {
               make leftButton get touched....
        }
}

Hello.

I would also like to know how generate a touch event.
If you found any solution, let me know please.

Hi, which platform you want to simulate a touch event, you can look at CCEGLView::WindowProc method of CCEGLView_win32.cpp if you just want to achieve that on win32.

LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
...
    case WM_KEYDOWN:
        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 (wParam == VK_F3)
        {
            SendMessage(m_hWnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(480-10, 320-10));// your left button postion
            SendMessage(m_hWnd, WM_LBUTTONUP, MK_LBUTTON, MAKELONG(480-10, 320-10));
        }
        break;
...

This is awesome, I’ll try it once I have time. Thanks James thumbs up!