What would be the equivalent for Mouse.GetPostion(null) which is in WPF.
I can get the position of pointer from the pointer event args. but how do i get the position without any event. like "Mouse.GetPostion(null)" in WPF. where mouse is a static class.
Any idea?
There is a PointerPoint.Position property - PointerPoint is a general input abstraction that also inludes touch and stylus input so you have to get a focus on mouse input first - this can be done with a static
PointerPoint PointerPoint.GetCurrentPoint(uint pointerId)
method where pointerId is a system generated number identifying the input device. I don't know if there is any other way but you can get the mouse PointerId through
PointerRoutedEventArgs.Pointer.PointerId
if you handle some mouse Pointer event like PointerPressed or PointerReleased first.
Related
I need to filtrate touch point in an UWP app. I need to filtrate touch point according to timestamp of a touch point, and get coordinate or id of the touch point.
In a WPF application , I can get necessary data of touch point by using TouchFrameEventArgs class, and using the method GetTouchPoints().
But, In UWP app, what should I use? I want to get the first occurred touch point after a specific event occurs.
First, generally speaking, touhc, mouse and pen input in UWP is abstracted to a single event set dealing with pointers.
When you handle a pointer event like PointerDown, you get an instance of PointerRoutedEventArgs class. This class will help you identify a specific pointer using the Pointer.PointerId property. This a unique identification you can use to check for the pointer that raised this event. You can store the pointer IDs you have encountered in time which should provide you with the behavior you are requesting.
I am working with ArcGIS SDK for dot net. I am programming using vc#. I want to execute a piece of code as soon as the mouse pointer enters a particular longitude/latitude on map or if mouse is clicked on that location. there are many event handlers but I don't know how to retrieve the location the mouse pointer is at. e.g I want to display some picture as soon as mouse pointer is at longitude 25 and lat 33.
Add a MouseMove listener to your MapView.
Your listener method will have a parameter of type MouseEventArgs. Call GetPosition(null) on that parameter to get the screen point.
Use MapView.ScreenToLocation(Point) to get the MapPoint in map coordinates.
If your map isn't in longitude/latitude, use GeometryEngine.Project(Geometry, SpatialReference.Create(4326)) to convert to longitude/latitude.
Check the longitude and latitude to see if they're in the range you want.
I tried posting my source code here but Stack Overflow gave me an error, so here it is as a screenshot:
I will like to know what can I do to track down the position of a second pointer which enter in the canvas.
I added a counter in the PointerEntered event handler. It's able to track how many pointers are there, but I don't know how to track the position of the second(or more) pointer as it moves.
Thank you in advance for any help.
The corresponding event provides event arguments that hold a reference to the Pointer. Each pointer instance has a separate pointer id:
Pointer Properties on MSDN
You need to also register with the PointerMoved event to get updates of the pointer location. Using the pointer ids, you can index into your local data structure to update the location of your visual on the canvas.
You cannot register for the events bound to a specific pointer ID. All events will be triggered for all pointers. So you only register once with the events, normally. You need to keep track (e.g. via a Dictionary from pointer id to your pointer data) of each pointer in your own code if you need to handle each pointer input differently. The MSDN Pointer Tutorial has a nice example that shows exactly that.
I know how to stimulate clicks using User32 SendInput method and what I need is a similar User32 method but to obtain the current mouse button state.
Something similar to:
public static extern bool GetCursorPos(ref System.Drawing.Point lpPoint);
Function GetCursorPos gives me the current cursor position. What I need is the left button state (if it's clicked or not). Is there such a function?
Use GetAsyncKeyState, To Quote MSDN:
The GetAsyncKeyState function works
with mouse buttons. However, it checks
on the state of the physical mouse
buttons, not on the logical mouse
buttons that the physical buttons are
mapped to. For example, the call
GetAsyncKeyState(VK_LBUTTON) always
returns the state of the left physical
mouse button, regardless of whether it
is mapped to the left or right logical
mouse button. You can determine the
system's current mapping of physical
mouse buttons to logical mouse buttons
by calling
GetSystemMetrics(SM_SWAPBUTTON).
There's a method called GetAsyncKeyState. The method signature looks like this:
[DllImport("user32.dll")]
public static extern short GetAsyncKeyState(UInt16 virtualKeyCode);
Then you simply call it passing the left mouse key code (VK_LBUTTON = 0x01) and off you go.
More information directly from MSDN.
... Is it possible to create hot-spots in C# so that when the mouse is over a certain area an event gets triggered?
Your standard From object exposes a OnMouseMove event. Given that you don't have any controls where the hot spots will be, you could just handle the coordinates in that event:
protected override void OnMouseMove(MouseEventArgs mouseEvent)
{
string X = mouseEvent.X.ToString();
string Y = mouseEvent.Y.ToString();
//Add code here to match X & Y to your hot spot coordinates.
}
Create a transparent Panel (truly transparent - by setting the WS_EX_TRANSPARENT bit in its extended window style - here's how), put it in the position you want on top of other controls, and handle MouseMove on it.
Add a MouseHover event handler for the control(s) that you want your hotspot over.
You can use WndProc to capture windows messages, or you could use GetCursorPos to get the cursor position on the screen.