Mouse position

Post comments and suggestions for RoboTask here
Post Reply
VicFan
Posts: 3
Joined: Mon Aug 09, 2021 1:20 pm

Mouse position

Post by VicFan »

It would be really helpful to add a function to save the current mouse position (absolute X-Position and absolute Y-Position) into 2 variables. This could allow the script to return the mouse to whatever position it has previously been at by using the Mouse Move function with those 2 variables.
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Mouse position

Post by Oleg »

You can do this right now.
Look at my example
Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
Do not forget to enable the task after importing.

To run the task press CTRL+ALT+P. the task saves the mouse position and restores at the end of task.

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1163085779
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
Events=FOLDER
ExternalName=STRING|"Task1179"
Hide=INTEGER|0
ID=INTEGER|-273600315
LogOnAsUser=INTEGER|1
Name=STRING|"Save mouse position"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""xpos"" with value ""{MouseX}"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"1"
varname=STRING|"xpos"
varvalue=STRING|"{MouseX}"

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""ypos"" with value ""{MouseY}"""
Params=FOLDER

[Actions\Action2\Params]
expand=STRING|"1"
varname=STRING|"ypos"
varvalue=STRING|"{MouseY}"

[Actions\Action3]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Press OK to show saved mouse position"""
Params=FOLDER

[Actions\Action3\Params]
icon=STRING|"1"
msg0=STRING|"Press OK to show saved mouse position"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action4]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action4\Params]
message=STRING|"Saved position x={xpos}; y={ypos}"
type=STRING|"3"

[Actions\Action5]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Saved position"""
Params=FOLDER

[Actions\Action5\Params]
icon=STRING|"1"
msg0=STRING|"Saved position"
msg1=STRING|"x = {xpos}"
msg2=STRING|"y = {ypos}"
msg4=STRING|"press OK to restore position "
msgcount=STRING|"5"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action6]
ActionID=STRING|"A_MOUSE_MOVE"
Enabled=INTEGER|-1
Name=STRING|"Move"
Params=FOLDER

[Actions\Action6\Params]
dx=STRING|"{xpos}"
dy=STRING|"{ypos}"
mode=STRING|"0"

[Events]
Event1=FOLDER

[Events\Event1]
Enabled=INTEGER|-1
EventID=STRING|"E_GENERAL_HOTKEY"
Name=STRING|"Ctrl+Alt+P"
Params=FOLDER
UniqueID=INTEGER|-334513961

[Events\Event1\Params]
hotkey=STRING|"49232"

Oleg Yershov
VicFan
Posts: 3
Joined: Mon Aug 09, 2021 1:20 pm

Re: Mouse position

Post by VicFan »

It is during the task that I want to save the mouse position, not just restore the mouse to position before the script executes.

Here is a use case: during execution the script an object is deleted and I want to create another object of a different type in same place as the original. The script can't do that because the object no longer exists that it found the original position to begin with.
VicFan
Posts: 3
Joined: Mon Aug 09, 2021 1:20 pm

Re: Mouse position

Post by VicFan »

Sorry, please delete my reply asking how to do it during the script. I just read your reply and didn't try the code. Sorry
Post Reply