Prevent touch input moving mouse cursor on Windows - c++

I'm writing a C++ Win32 application that supports both mouse and touch input.
However when I put my finger on the touchscreen, then the OS moves the mouse cursor into that position.
If I move the finger across the screen, and move the mouse at the same time, then OS will cause mouse cursor flickering, one frame it's under finger, 2nd frame under old mouse position.
I want the touch input to stop changing mouse cursor position.
I want to keep the 2 inputs separate - touch not affecting the mouse.
I want to keep reading 2 inputs at the same time - touch not affecting the mouse.

Here's a solution.
Use WH_MOUSE_LL hook, and block mouse event cause by touching. Then compare MSLLHOOKSTRUCT->dwExtraInfo and 0xFF515700 to determine if it's a touch-caused mouse event.

Related

Is there an SFML delta mouse movement event?

I'm trying to implement a way to click and drag the screen in SFML. The idea being that when the user clicks down on their mouse, an sf::View gets changed by how much the user moves their mouse until they release it.
I tried to use the sf::Event::MouseMoveEvent struct under the assumption it would give the mouse movement and not the position. When I used it in code, however, it gets the position.
I could try and keep track of the previous mouse position and subtract it out to get the change, but I would expect that there would be a struct or function that would give me the delta position. It has this functionality for the scroll wheel, so I'd hope it does for the mouse.

SDL/c++ drawing by holding mouse button

I'm new in working with SDL and now I've faced a problem.
Well, I'm about to make a program like Paint.
In order to do that I need a command for mouse that when I'm holding the left button and moving the mouse, a line would be drawing in where the mouse is going.
I have found an event for it, SDL_MouseButtonDown. but it only works for one second like I only click on the screen for one time!
I will appreciate any comments!
The event fires when the button goes down. It doesn't repeatedly fire for as long as the button is down, and this wouldn't be of much use to you anyway.
Write your code so that you set some variable when the button goes down, and unset it when SDL_MouseButtonUp is invoked. Whenever the mouse moves, and your variable is set, draw more of the line.

Qt mouseMoveEvent - tracking mouse position

I'm programming my first 2D game in Qt.
I have QWidged where I draw my game (isometric view). When mouse enters border of widget it moves map view (like in every strategy game...).
And here is my trouble... I'm tracking mouse position with mouseMoveEvent but it fires only when mouse moves (only when position changes). So map moves only when I move mouse at borders. If mouse stand still, map does not move (mouseMoveEvent is not triggered). And I have no idea how to solve this. It's annoying when you try to play it.
This is my first post here.. and I hope that I explained my problem clearly :)
Edit (little more clarify):
Imagine this: you want to move map. So you move mouse to the edge of screen (QWidget) but at the moment when you stop mouse, map stops moving too. But mouse is still at edge of screen. What I want to do is that map will still move after mouse stops at edge.
You can create QPropertyAnimation for coordinates and start/stop it when mouse moves to/from widget's border.
Or you can remember current state ("changing x by -1 every 100ms, changing y by 0") and call some slot that does the real moving with QTimer.

Weird cursor behavioir in Qt

In Qt (C++, MinGW, Windows 7), QCursor::setPos(...) seems to change the position of the cursor at the application level but not at the system level. For example, if you intercept the mouseMoveEvent and cancel out the movement of the cursor (with setMouseTracking(false) such that you do this cancellation only when a mouse button is pressed), then you'll see no cursor move as long as you maintain the mouse button pressed. But then, when you release the button and move a little, the cursor will go to the place it would have been if you haven't blocked its movement. Is this behavior normal? How to get around it such that the mouse cursor is changed at the system level?
If it is not clear enough, I can give code snippet.
Moving the cursor of a QWidget always uses the widget's coordinates. For global mouse positioning, you should use the desktop widget (QDesktopWidget) instead. You can get it through the QApplication::desktop() static function. Example:
QApplication::desktop()->cursor().setPos(0,0);
This should move the mouse cursor to the top-left corner of the desktop.

Getting mouse cursor position and button state on Windows

What is the most appropriate way of getting the mouse cursor position or button state on Windows (Windows 7 and above)? I previously used DirectInput, but I am not longer using it and do not wish to. I saw there is GetCursorPos, however, I do not see anything for getting mouse button states. I have read previously that just reading the window messages (such as WM_LBUTTONUP) was considered "slow" for real time applications, so I do not know of any other option.
If you want to poll/query the current cursor position, you can use GetCursorPos. To see the button states, use GetAsyncKeyState.
If you are implementing a message loop in a window, the notification you will get for a mouse movement is WM_MOUSEMOVE. You will be notified of mouse inputs through the notifications listed here.
WM_LBUTTONUP is as good as any window message, for windowed games is great because it is generated only when the mouse clicks the client area, so you can resize and move the window freely.
As an alternative to direct input, you can use raw inputs which take up some more code to initialize, but it's the best way to go with the mouse movement since WM_INPUT is generated when the physical mouse moves, not the cursor, so you can clip the cursor in the client area without worrying that the user may hit the side of the clip rect and the mouse movement messages won't be generated anymore.
link