Solved

Convert pixels to mouse position in browser

Posted on 2011-03-09
3
527 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

828 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