Empirisoft Support

    Welcome to Empirisoft Support
Results 1 to 6 of 6

Thread: Get mouse position using custom forms (case 12064)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Get mouse position using custom forms (case 12064)

    Hi,
    Could anyone help me to return the x and y coordinates for a mouse click using an HTML form in Medialab using the custom feature? We need a blank square which covers the greater percentage of the screen that can be clicked on in any location to guess where an object is hidden. Bit like battleships but only one shot.

    I found the following HTML Javascript code which I was trying modify and use:

    <!doctype html>

    <html>
    <head>
    <title>Get the coordinates on canvas</title>
    <meta charset="utf-8" />

    <style type="text/css">

    #canvas{background-color: #000;}

    </style>

    <script type="text/javascript">

    document.addEventListener("DOMContentLoaded", init, false);

    function init()
    {
    var canvas = document.getElementById("canvas");
    canvas.addEventListener("mousedown", getPosition, false);
    }

    function getPosition(event)
    {
    var x = new Number();
    var y = new Number();
    var canvas = document.getElementById("canvas");

    if (event.x != undefined && event.y != undefined)
    {
    x = event.x;
    y = event.y;
    }
    else // Firefox method to get the position
    {
    x = event.clientX + document.body.scrollLeft +
    document.documentElement.scrollLeft;
    y = event.clientY + document.body.scrollTop +
    document.documentElement.scrollTop;
    }

    x -= canvas.offsetLeft;
    y -= canvas.offsetTop;

    alert("x: " + x + " y: " + y);
    }

    </script>

    </head>

    <body>
    <canvas id="canvas" width="640" height="360"></canvas>
    </body>
    </html>
    Last edited by jason_reed; 12-17-2013 at 05:43 PM.

Similar Threads

  1. Continous mouse position
    By rkreager in forum Hardware: How Do I...
    Replies: 3
    Last Post: 03-25-2021, 04:50 AM
  2. Resetting the mouse cursor position in between trials (case 1743)
    By gerardo in forum DirectRT v2018: How Do I...
    Replies: 2
    Last Post: 03-21-2013, 05:16 PM
  3. position and size of html in custom items
    By MandaHyde in forum MediaLab Older Versions: How Do I...
    Replies: 2
    Last Post: 10-29-2009, 12:43 PM
  4. Mouse position
    By rothers27 in forum MediaLab Older Versions: How Do I...
    Replies: 2
    Last Post: 07-08-2008, 04:09 PM
  5. custom item for tracking XY joystick/mouse movements
    By surpass in forum MediaLab Older Versions: How Do I...
    Replies: 3
    Last Post: 12-06-2007, 09:12 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •