# Mouse coordinates but relative to dialog's window

**URL:** https://resource.dopus.com/t/mouse-coordinates-but-relative-to-dialogs-window/54550
**Category:** Help & Support
**Tags:** script, feature-request
**Created:** [February 15, 2025, 9:54pm UTC](https://resource.dopus.com/t/mouse-coordinates-but-relative-to-dialogs-window/54550 "2025-02-15T21:54:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![errante](https://resource.dopus.com/user_avatar/resource.dopus.com/errante/32/61692_2.png) [@errante](https://resource.dopus.com/u/errante)
#### Post date: [February 15, 2025, 9:54pm UTC](https://resource.dopus.com/t/mouse-coordinates-but-relative-to-dialogs-window/54550/1 "2025-02-15T21:54:35Z")

</div>

Currently you can get mouse coordinates when reacting to an event in a script dialog via the `Msg` object, but these are relative to the screen rather than the dialog itself. Although you can do some math to convert these coordinates to be relative to the dialog, it would only be an approximation because there are unknowns (like the titlebar height, etc.).

Is there any way to achieve that? I want to show a control exactly where the mouse pointer is (Assuming that its coordinates are within the space of the dialog window in question).

---

<div class="post-metadata">

### Author: ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)
#### Post date: [February 19, 2025, 6:14pm UTC](https://resource.dopus.com/t/mouse-coordinates-but-relative-to-dialogs-window/54550/2 "2025-02-19T18:14:50Z")

</div>

We'll add methods for this in the next beta.

Example of how it can be used:

 ![image](https://resource.dopus.com/uploads/default/original/3X/a/4/a4ed312a00724aef94644615da470a8390ed3de6.png)

Script Code:

```javascript
function OnClick(clickData)
{
	var dlg = DOpus.Dlg();
	dlg.window = clickData.func.sourcetab;
	dlg.template = "mousePosDialog";
	dlg.detach = true;
	dlg.Create();
	dlg.SetTimer(100, "mouseTimer");
	dlg.Show();

	var ctrlSX = dlg.Control("staticSX");
	var ctrlSY = dlg.Control("staticSY");
	var ctrlCX = dlg.Control("staticCX");
	var ctrlCY = dlg.Control("staticCY");

	while(true)
	{
		var msg = dlg.GetMsg();
		if (!msg.result)
			break;
		if (msg.control == "mouseTimer")
		{
			var t = dlg.ScreenToClient(msg.mousex, msg.mousey);
			ctrlSX.label = String(msg.mousex);
			ctrlSY.label = String(msg.mousey);
			ctrlCX.label = String(t.left);
			ctrlCY.label = String(t.top);
		}
	}
}

```

Resources:

```xml
<resources>
	<resource name="mousePosDialog" type="dialog">
		<dialog height="48" lang="english" title="Mouse Pos Example" width="114">
			<control halign="left" height="8" name="static1" title="Screen:" type="static" valign="top" width="30" x="12" y="12" />
			<control halign="center" height="8" name="staticSX" title="SX" type="static" valign="top" width="20" x="48" y="12" />
			<control halign="left" height="8" name="static4" title="x" type="static" valign="top" width="6" x="72" y="12" />
			<control halign="center" height="8" name="staticSY" title="SY" type="static" valign="top" width="20" x="84" y="12" />
			<control halign="left" height="8" name="static2" title="Client:" type="static" valign="top" width="30" x="12" y="30" />
			<control halign="center" height="8" name="staticCX" title="CX" type="static" valign="top" width="20" x="48" y="30" />
			<control halign="left" height="8" name="static5" title="x" type="static" valign="top" width="6" x="72" y="30" />
			<control halign="center" height="8" name="staticCY" title="CY" type="static" valign="top" width="20" x="84" y="30" />
		</dialog>
	</resource>
</resources>

```

---

<div class="post-metadata">

### Author: ![errante](https://resource.dopus.com/user_avatar/resource.dopus.com/errante/32/61692_2.png) [@errante](https://resource.dopus.com/u/errante)
#### Post date: [February 26, 2025, 11:37pm UTC](https://resource.dopus.com/t/mouse-coordinates-but-relative-to-dialogs-window/54550/3 "2025-02-26T23:37:05Z")

</div>

Many thanks!
