Solved

Convert pixels to mouse position in browser

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
paypal ipn url 5 52
ASP.net File format issue in producing Excel file 3 30
Changing Web Hosts: Need Your Expert Opinion & Ideas 6 32
Expression Evaluater 3 24
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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…
This video teaches users how to migrate an existing Wordpress website to a new domain.

813 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

11 Experts available now in Live!

Get 1:1 Help Now