Jump to content
Sign in to follow this  
TiGGa

Getting the mouse cursor position on screen

Recommended Posts

Hi,

I want to obtain the mouse position on the screen in order to use it with the screentoworld command. It seems there isn't a script command for that.

I've looked into the UI event handlers, but couldn't find exactly what I like. The onMouseButtonDown event does return the screen, but I'd have to constantly click the button for a non-stop mouse position tracking.

The onMouseMoving doesn't require any keys pressed, but the return value isn't an absolute position on screen. Instead the event will return the distance your mouse has traveled since the the last time the event has fired. -_-

I've tried to calculate the mouse position with posx = posx + _this select 1, but return value is far to inaccurate on fast mouse movements.

Does anyone have an idea or solution?

Share this post


Link to post
Share on other sites

what about cursorTarget

i didnt check yet what it reports

edit: ok doesnt give a position. only the targeted, if any, object.

Edited by kju

Share this post


Link to post
Share on other sites

MouseMoving should work just fine.

Try it like this:

_control ctrlSetEventHandler ["MouseMoving","nul=[_this select 1,_this select 2] execVM ""mouse.sqf"" "];

Thats how I normally use it and it works.

Share this post


Link to post
Share on other sites

Whats mouse.sqf? Is it an internal BIS script?

The problem is that _this doesn't give you the screen coordinats at all! _this select 1 and 2 is some kind of value, which is small when moving slowly and huge when moving the mouse fast.

We definitely need a "GetMousePosition" command. I mean, there is already a "setMousePosition" command without a counterpart... tell me the logic.

Edited by TiGGa

Share this post


Link to post
Share on other sites

Like I said, I've been using it for a while and had no problems with it. Mouse.sqf is just a script of mine where i pass the values to

I don't believe the eventhandler returns the mousespeed, guess its necessary to test that. All I know is that the script which I made for ArmA1, using this eventhandler still works.

Can you post an codeexample, how you use it ?

Share this post


Link to post
Share on other sites

Well not exactly the mouse speed, but it is considering the mouse accelerating. Move your mouse slowly to the left and _this select 1 will be about -0.0xxx, but move it fast to the left and it will be 100.0+. This is impossibly the screen coordinat for the x axis. The screen goes from 0 (left side) to 1.0 (right side). Maybe they have changed something since Arma1.

Create the following display with _disp=createDialog "Test";

class Test

{

idd = 9000;

movingEnable = true;

onMouseMoving = "hintSilent format [""%1"",_this];player setdir (getdir player + (_this select 1))";

onLoad = "";

onUnload = "";

controlsBackground[] = {};

objects[] = { };

controls[] = { };

};

Just look at the hint message.

Edited by TiGGa

Share this post


Link to post
Share on other sites
goes from 0 (left side) to 1.0 (right side)

this doesn't apply for arma2 anymore. Now that they allow you to scale your interface, these numbers can differ.

I'll have to have a close look on this, when I get home.

does "onMouseHolding" have the same issue ?

However, I've noticed that setDir-command. What is it you want to do with this script ? Maybe theres a different solution.

Share this post


Link to post
Share on other sites

Yes I know, but even setting the interface to the smallest setting, an x-value of over 100 is ridiculous. And yes, the holding event has the same issue.

The setdir command is there just to visually see that the event is considering the mouse acceleration.

Obviously, there was a way in Arma1:

You can see how the building is following the mouse cursor. I'm trying to recreate that for my own upcoming RTS mission. As I said before, onMouseButtonDown works well. The coordinates in _this are precise, but I can't have a continuous tracking of the mouse position with that event.

Edited by TiGGa

Share this post


Link to post
Share on other sites

More or less ripped from the "armory"...

class RscActiveText
{
access = 0;
type = 11;
style = 2;
color[] = { 0, 0, 0, 1 };
colorActive[] = { 0.3, 0.4, 0, 1 };
soundEnter[] = { "", 0.1, 1 };
soundPush[] = { "", 0.1, 1 };
soundClick[] = { "", 0.1, 1 };
soundEscape[] = { "", 0.1, 1 };
text = "";
default = 0;
idc = -1;
x = 0;
y = 0;
h = 0.035;
w = 0.035;
font = "Zeppelin32";
sizeEx = 0.03921;
colortext[] = { 0, 0, 0, 1 };
};

class Test
{
idd = -1;
class Controls {
	class foo : RscActiveText {
		idc = -1;
		style = 48;
		x = -1;
		y = -1;
		w = 3;
		h = 1.9;
		text = "#(argb,8,8,3)color(1,1,1,1)";
		color[] = {0, 0, 0, 0};
		colorActive[] = {0, 0, 0, 0};
		onMouseMoving = "hintSilent format ['%1\n%2',_this select 1, _this select 2];";
	};
};
};

HTH

Share this post


Link to post
Share on other sites

You are my hero. Thank you soooooo |---------------| much. :)

Edit:

x = SafeZoneX;

y = SafeZoneY;

w = SafeZoneW;

h = SafeZoneH;

Edited by TiGGa

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×