Solved

Convert pixels to mouse position in browser

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
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…
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.

930 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

10 Experts available now in Live!

Get 1:1 Help Now