示例#1
0
void MouseReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
{
    MOUSEINFO	*pmi = (MOUSEINFO*)buf;

    if (prevState.mouseInfo.bmLeftButton == 0 && pmi->bmLeftButton == 1)
        OnLeftButtonDown(pmi);

    if (prevState.mouseInfo.bmLeftButton == 1 && pmi->bmLeftButton == 0)
        OnLeftButtonUp(pmi);

    if (prevState.mouseInfo.bmRightButton == 0 && pmi->bmRightButton == 1)
        OnRightButtonDown(pmi);

    if (prevState.mouseInfo.bmRightButton == 1 && pmi->bmRightButton == 0)
        OnRightButtonUp(pmi);

    if (prevState.mouseInfo.bmMiddleButton == 0 && pmi->bmMiddleButton == 1)
        OnMiddleButtonDown(pmi);

    if (prevState.mouseInfo.bmMiddleButton == 1 && pmi->bmMiddleButton == 0)
        OnMiddleButtonUp(pmi);

    if (prevState.mouseInfo.dX != pmi->dX || prevState.mouseInfo.dY != pmi->dY)
        OnMouseMove(pmi);

    for (uint8_t i=0; i<3; i++)
        prevState.bInfo[i] = buf[i];
};
示例#2
0
void Application::GetInput(int message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_MOUSEMOVE:
        {
            POINT m;
            m.x = GET_X_LPARAM(lParam);
            m.y = GET_Y_LPARAM(lParam);

            mouse.Update(m.x, m.y);
        }
        break;
    case WM_LBUTTONDOWN:
        OnLeftButtonDown();
        break;

    case WM_MOUSEWHEEL:
        OnRightButtonDown();
        break;

    default:
        return;
    }
}
示例#3
0
void MouseReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
        MOUSEINFO *pmi = (MOUSEINFO*)buf;
        // Future:
        // bool event;

#if 0
        if (prevState.mouseInfo.bmLeftButton == 0 && pmi->bmLeftButton == 1)
                OnLeftButtonDown(pmi);

        if (prevState.mouseInfo.bmLeftButton == 1 && pmi->bmLeftButton == 0)
                OnLeftButtonUp(pmi);

        if (prevState.mouseInfo.bmRightButton == 0 && pmi->bmRightButton == 1)
                OnRightButtonDown(pmi);

        if (prevState.mouseInfo.bmRightButton == 1 && pmi->bmRightButton == 0)
                OnRightButtonUp(pmi);

        if (prevState.mouseInfo.bmMiddleButton == 0 && pmi->bmMiddleButton == 1)
                OnMiddleButtonDown(pmi);

        if (prevState.mouseInfo.bmMiddleButton == 1 && pmi->bmMiddleButton == 0)
                OnMiddleButtonUp(pmi);

        if (prevState.mouseInfo.dX != pmi->dX || prevState.mouseInfo.dY != pmi->dY)
                OnMouseMove(pmi);

        if (len > sizeof (MOUSEINFO))
                for (uint8_t i = 0; i<sizeof (MOUSEINFO); i++)
                        prevState.bInfo[i] = buf[i];
#else
        //
        // Optimization idea:
        //
        // 1: Don't pass the structure on every event. Buttons would not need it.
        // 2: Only pass x/y values in the movement routine.
        //
        // These two changes (with the ones I have made) will save extra flash.
        // The only "bad" thing is that it could break old code.
        //
        // Future thoughts:
        //
        // The extra space gained can be used for a generic mouse event that can be called
        // when there are _ANY_ changes. This one you _MAY_ want to pass everything, however the
        // sketch could already have noted these facts to support drag/drop scroll wheel stuff, etc.
        //

        // Why do we need to pass the structure for buttons?
        // The function call not enough of a hint for what is happening?
        if(prevState.mouseInfo.bmLeftButton != pmi->bmLeftButton ) {
                if(pmi->bmLeftButton) {
                        OnLeftButtonDown(pmi);
                } else {
                        OnLeftButtonUp(pmi);
                }
                // Future:
                // event = true;
        }

        if(prevState.mouseInfo.bmRightButton != pmi->bmRightButton) {
                if(pmi->bmRightButton) {
                        OnRightButtonDown(pmi);
                } else {
                        OnRightButtonUp(pmi);
                }
                // Future:
                // event = true;
        }

        if(prevState.mouseInfo.bmMiddleButton != pmi->bmMiddleButton) {
                if(pmi->bmMiddleButton) {
                        OnMiddleButtonDown(pmi);
                } else {
                        OnMiddleButtonUp(pmi);
                }
                // Future:
                // event = true;
        }

        //
        // Scroll wheel(s), are not part of the spec, but we could support it.
        // Logitech wireless keyboard and mouse combo reports scroll wheel in byte 4
        // We wouldn't even need to save this information.
        //if(len > 3) {
        //}
        //

        // Mice only report motion when they actually move!
        // Why not just pass the x/y values to simplify things??
        if(pmi->dX || pmi->dY) {
                OnMouseMove(pmi);
                // Future:
                // event = true;
        }

        //
        // Future:
        // Provide a callback that operates on the gathered events from above.
        //
        // if(event) OnMouse();
        //

        // Only the first byte matters (buttons). We do NOT need to save position info.
        prevState.bInfo[0] = buf[0];
#endif

};
示例#4
0
/*
This should only be called from the main game loop before the rest of the game is updated
for the frame otherwise it may cause in intended behavior. It will poll both the keyboard
and mouse states and then save them into easily accessible structs.
*/
void Input::PollEvents(float elapsedTime)
{
	if(previousMouseInfo.button == mouseInfo.button && previousMouseInfo.state == KeyState::Pressed && mouseInfo.state == KeyState::Pressed)
	{
		mouseInfo.state = KeyState::Held;
	}
	else
	{
		previousMouseInfo = mouseInfo;
	}

	if(previousKeyInfo.decimal == keyInfo.decimal && previousKeyInfo.state == KeyState::Pressed && keyInfo.state == KeyState::Pressed)
	{
		keyInfo.state = KeyState::Held;
		AddToKeyHistory(keyInfo);
	}
	else if (previousKeyInfo.state == KeyState::Released && keyInfo.state == KeyState::Released)
	{
		keyInfo.Reset();
	}
	else
	{
		previousKeyInfo = keyInfo;
	}

	MSG msg;
	if (PeekMessage(&msg,0,0,0, PM_NOREMOVE))
	{
		switch(msg.message)
		{
		case WM_KEYDOWN:
			OnKeyDown(msg.wParam, elapsedTime);
			break;
		case WM_KEYUP:
			OnKeyUp(msg.wParam, elapsedTime);
			break;
		case WM_LBUTTONDOWN:
			OnLeftButtonDown(msg.wParam, elapsedTime);
			break;
		case WM_LBUTTONUP:
			OnLeftButtonUp(msg.wParam, elapsedTime);
			break;
		case WM_RBUTTONDOWN:
			OnRightButtonDown(msg.wParam, elapsedTime);
			break;
		case WM_RBUTTONUP:
			OnRightButtonUp(msg.wParam, elapsedTime);
			break;
		}

		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	sf::Event event;
	while (window->pollEvent(event))
	{
		if(event.type == sf::Event::Closed)
			window->close();
	}


	mouseInfo.mousePosition = sf::Mouse::getPosition((*window));
}