Solved

Convert pixels to mouse position in browser

Posted on 2011-03-09
3
530 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

739 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