Solved

Convert pixels to mouse position in browser

Posted on 2011-03-09
3
521 Views
Last Modified: 2012-05-11
I capture the current mouse position in javascript by getting the x and y pixels. I am trying to then call an ASP.NET method with PageMethods and pass the coordinates. I believe the mouse_event is using a different coordinate system. How do I convert from pixels in a browser to the coordinates that the mouse_event is expecting? In my C# code I am doing the following:
 
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

        public const int MOUSEEVENTF_LEFTDOWN = 0x02;
        public const int MOUSEEVENTF_LEFTUP = 0x04;
        public const int MOUSEEVENTF_RIGHTDOWN = 0x08;
        public const int MOUSEEVENTF_RIGHTUP = 0x10;

        [System.Web.Services.WebMethod]
        public static void MouseClick(int x, int y)
        {
            mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
            mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
        }
 

Open in new window


0
Comment
Question by:hwsitservices
  • 2
3 Comments
 
LVL 14

Expert Comment

by:robasta
ID: 35399781
0
 

Accepted Solution

by:
hwsitservices earned 0 total points
ID: 35416138
Sorry, I have not updated this earlier. What I ended up doing is..
function mouseClick(e) 
{
   var element = document.elementFromPoint(e.clientX, e.clientY);
   var evt = document.createEvent("MouseEvents");
   evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
   element.dispatchEvent(evt);
}

Open in new window

0
 

Author Closing Comment

by:hwsitservices
ID: 35452275
provided alternate solution
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now