I need help with mouse drag and drop. I would like to make something like mouse macro. You specify the XY coordinates of cursor and then drag something to another XY coordinates automatically. Is it possible?
I know how to simulate Mouse Click and Mouse Movement, but I am not sure with the Mouse Dragging.
WM_MOUSEDOWN, WM_MOUSEMOVE, WM_MOUSEUP -- use Spy++ to view windows messages
Related
I am developing a WPF application, where I need to allow user to rearrange objects by drag-drop. It is basically dragging objects within a canvas area and moving them to another area of the canvas. The mouse cursor would change to a drag cursor while dragging is happening.
The requirement is like the mouse pointer cannot leave the canvas area while the dragging is in progress. For that I am using the Win32 ClipCursor api to restrict the cursor to a certain boundary of the screen.
This is working fine when mouse is used. However, if touch is used, i.e. if the pointer is moved through touch, it is possible to take the cursor out of the bounding rectangle. Can anyone please help to understand why it is happening? I am handling the PreviewMouseMove and MouseLeftButtonUp events for starting and ending the drag. Do I need to handle the Touch and the Stylus events as well?
Thanks!
I have a C# control that has an scroll.
When a user drag and drop, the scrolls are updated. I would like to animate the drag&drop movement like google maps does. The movement is smoothly animated.
What technique must I use if want to simulate a swipe in the control, and perform a smoothly animated?
What I was looking for was the easing equations: http://www.gizma.com/easing
I'm working on a miniature golf game in XNA, I originally had everything in Game.cs (main), but I now want it to be more object-oriented, so I made separate class for most of my stuff.
When I had everything in Game.cs, it was working fine, now it doesn't.
What is happening is this:
When my cursor is at the top left corner of the game window, it's like X=200, Y=50.
It's supposed to be X=0, Y=0.
Even when I look for the 0, 0 position, it's way outside the game window.
Does anyone know what could be causing this?
How is that possible? Your cursor position is the mouse position. Simply draw the cursor there.
Unless you are talking about the Windows cursor. In that case, yes, the input data in XNA will not match the Windows cursor movement. They probably apply some modifiers for acceleration, etc. You have to interprete the input data yourself. In other words, draw your own cursor.
I am making a map editor for my games. I had already managed to add an object to the map when the user clicks on the map. It would be handy for me to add objects in a path the user clicks mouse and drags (like the pencil in mspaint). What events do I need to register to give that effect?
Thanks for any ideas.
Here is the main idea :
use MouseUp() MouseDown() and MouseMove() .
Set some bool to 0 - tell you if you are Dragging.
When (mouse Down) and (flag==0) then START_DRAGGING.
Then mouse move knows if you are dragging by flag==1.
When (mouse UP) and (flag == 1) you know youv'e just stopped dragging, so set flag to 0 again.
I'm working with a WPF app, more specifically a Canvas with draggable elements.
Once an item is being dragged, I'd like to limit the scope of cursor movement to inside the canvas where the items are being dragged about.
The event which can start a drag is shown below
private void WidgetCanvas_PreviewHeaderLeftMouseDown(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
... logic to figure out if this is a valid drag, blah blah blah ...
this.IsDragging = true;
// TODO: clip the available cursor movement to actual width of Canvas
}
On the Preview-MouseUp, I'd like to simply "unclip" the cursor movement back to it's normal state.
I'll be monitoring the movement of the mouse once I start dragging (PreviewMouseMove), so worst case, I could manually check the position of the mouse and keep it constrained to the canvas, but that seems a little ugly.
Anyone have a better way to limit the cursor boundaries?
There's no clean way to do this and the not-so-clean ways will make your mouse cursor "jitter" at the border of the clipping area.
Moreover, I'd question if this is really a good idea. The user should really own the mouse and he or she generally gets frustrated when you try to artificially limit things that he or she owns.
If you want to provide feedback when the mouse leaves your canvas, maybe you could leave the item being dragged stuck along the border while the mouse button is still down? This would tell the user that he or she has left the target area without trying to impose limitations on where the mouse can go.
Good luck!
You should be able to do it using the ClipCursor native API.