예제 #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
LRESULT TrayIcon::OnTrayIconMessage(HWND /*hWnd*/, UINT /*message*/, WPARAM /*wParam*/, LPARAM lParam)
{
   switch(lParam)
   {
   case WM_RBUTTONDOWN:
   case WM_CONTEXTMENU:
      OnContextMenu();
      break;

   case WM_LBUTTONDOWN:
      OnLeftButtonDown();
      break;
   }

   return 0;
}
예제 #4
0
LRESULT NFOView::ControlMessageProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
        case WM_LBUTTONDOWN:
            OnLeftButtonDown();
            break;
        case WM_LBUTTONUP:
            CopySelectedText();
            break;
        case WM_RBUTTONDOWN:
            break;
        case WM_SIZE:
            CheckScrollbar();
            break;
        case WM_HSCROLL:
        case WM_VSCROLL:
            DrawHyperlink();
            break;
        case WM_TIMER:
            if (wParam = TIMER_CHECK_SELECTED)
                CheckSelect();
            break;
        case WM_MOUSEMOVE:
            {
                LRESULT result = CallWindowProc(_oldProc, hwnd, message, wParam, lParam);
                POINTS point = MAKEPOINTS(lParam);
                OnMouseMove(point);
                return result;
            }
        case WM_PAINT:
            {
                LRESULT result = CallWindowProc(_oldProc, hwnd, message, wParam, lParam);
                DrawHyperlink();
                return result;
            }
    }

    return CallWindowProc(_oldProc, hwnd, message, wParam, lParam);
}
예제 #5
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

};
예제 #6
0
//-----------------------------------------------------------------------------
// Name: OnMouseInput()
// Desc: Handles responding to any mouse input that is generated from
//       the mouse event being triggered.
//-----------------------------------------------------------------------------
VOID OnMouseInput( HWND hWnd )
{
    BOOL                bDone;
    DIDEVICEOBJECTDATA  od;
    DWORD               dwElements;
    HRESULT             hr;

    // Invalidate the old cursor so it will be erased 
    InvalidateCursorRect( hWnd );

    // Attempt to read one data element.  Continue as long as
    // device data is available.
    bDone = FALSE;
    while( !bDone ) 
    {
        dwElements = 1;
        hr = g_pMouse->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), 
                                      &od, &dwElements, 0 );

        if( hr == DIERR_INPUTLOST ) 
        {
            SetAcquire();
            break;
        }

        // Unable to read data or no data available
        if( FAILED(hr) || dwElements == 0 ) 
        {
            break;
        }

        // Look at the element to see what happened
        switch( od.dwOfs ) 
        {     
            case DIMOFS_X:       // Mouse horizontal motion 
                UpdateCursorPosition( od.dwData, 0 ); 
                break;

            case DIMOFS_Y:       // Mouse vertical motion 
                UpdateCursorPosition( 0, od.dwData ); 
                break;

            case DIMOFS_BUTTON0: // Right button pressed or released 
            case DIMOFS_BUTTON1: // Left button pressed or released 
                // Is the right or a swapped left button down?
                if( ( g_bSwapMouseButtons  && DIMOFS_BUTTON1 == od.dwOfs ) ||
                    ( !g_bSwapMouseButtons && DIMOFS_BUTTON0 == od.dwOfs ) )
                {
                    if( od.dwData & 0x80 ) 
                    { 
                        // left button pressed, so go into button-down mode 
                        bDone = TRUE;
                        OnLeftButtonDown( hWnd ); 
                    }
                }

                // is the left or a swapped right button down?
                if( ( g_bSwapMouseButtons  && DIMOFS_BUTTON0 == od.dwOfs ) ||
                    ( !g_bSwapMouseButtons && DIMOFS_BUTTON1 == od.dwOfs ) )
                {
                    if( !(od.dwData & 0x80) ) 
                    {  
                        // button released, so check context menu 
                        bDone = TRUE;
                        OnRightButtonUp( hWnd ); 
                    }
                }
                break;
        }
    }

    // Invalidate the new cursor so it will be drawn 
    InvalidateCursorRect( hWnd );
}
예제 #7
0
LRESULT CozyCaptureWindow::OnLeftButtonDownConvert(UINT   uMsg, WPARAM   wParam, LPARAM   lParam, BOOL&   bHandled)
{
    POINT cp{ GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
    ::ClientToScreen(m_hWnd, &cp);
    return OnLeftButtonDown(uMsg, wParam, Point2LPARAM(cp), bHandled);
}
예제 #8
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));
}