It is currently April 27th, 2024, 6:27 am

Lua Script Mouse Position

Get help with creating, editing & fixing problems with skins
FoxInTheClouds
Posts: 5
Joined: September 8th, 2023, 5:07 pm

Lua Script Mouse Position

Post by FoxInTheClouds »

Hello, I'd like to use a lua script to get the current mouse coordinates every update (and then use that in the rainmeter code). I'm not sure how to get the actual mouse coordinates in lua. I am very new to lua and Google isn't being helpful. Thanks!
User avatar
balala
Rainmeter Sage
Posts: 16174
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lua Script Mouse Position

Post by balala »

FoxInTheClouds wrote: September 18th, 2023, 6:34 pm I'd like to use a lua script to get the current mouse coordinates every update (and then use that in the rainmeter code).
You don't need a Lua script for this, but a plugin. Namely you need the Mouse plugin, available here. Install it.
Then you need to add the following measure and meter to your code:

Code: Select all

[MeasureMouse]
Measure=Plugin
Plugin=Mouse
DynamicVariables=1
MouseMoveAction=[!SetVariable PosX "$mouseX$"][!SetVariable PosY "$mouseY$"][!UpdateMeter "MeterPos"][!Redraw]
RelativeToSkin=1

[MeterPos]
Meter=STRING
X=10
Y=10
Padding=15,5,15,5
FontColor=220,220,220
FontEffectColor=0,0,0
StringEffect=Shadow
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=#PosX# | #PosY#
DynamicVariables=1
The PosX and PosY variables, which you can see in the [MeterPos] meter, are returning the position of mouse relative to the upper left corner of the skin.
Please let me know if you don1t know how to install the plugin.
FoxInTheClouds
Posts: 5
Joined: September 8th, 2023, 5:07 pm

Re: Lua Script Mouse Position

Post by FoxInTheClouds »

I don't really want to use a plugin if possible because I am giving the skin to non-techy people who often don't have the right dependecies (C++ runtime, .NET) and have run into issues.
User avatar
balala
Rainmeter Sage
Posts: 16174
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lua Script Mouse Position

Post by balala »

FoxInTheClouds wrote: September 18th, 2023, 8:16 pm I don't really want to use a plugin if possible because I am giving the skin to non-techy people who often don't have the right dependecies (C++ runtime, .NET) and have run into issues.
Sorry, but in this case, that's it. Not sure if you can do this by a Lua script.
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Lua Script Mouse Position

Post by Yincognito »

FoxInTheClouds wrote: September 18th, 2023, 8:16 pm I don't really want to use a plugin if possible because I am giving the skin to non-techy people who often don't have the right dependecies (C++ runtime, .NET) and have run into issues.
A Rainmeter plugin is just a .dll file that uses the same dependencies as Rainmeter itself, and can easily be included into your skin package when you pack your skin for release. In other words, all these non-technical people would have to do is to install your packaged skin via double clicking on it's .rmskin package, and theyll have everything you included there (the plugin as well) ready for use by your code.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
FoxInTheClouds
Posts: 5
Joined: September 8th, 2023, 5:07 pm

Re: Lua Script Mouse Position

Post by FoxInTheClouds »

I figured out the error I was getting on other computers, it was a different thing. Turns out a plugin works fine.
Thanks for the help.
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Lua Script Mouse Position

Post by Yincognito »

FoxInTheClouds wrote: September 19th, 2023, 3:53 pm I figured out the error I was getting on other computers, it was a different thing. Turns out a plugin works fine.
Thanks for the help.
:thumbup:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16174
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lua Script Mouse Position

Post by balala »

FoxInTheClouds wrote: September 19th, 2023, 3:53 pm I figured out the error I was getting on other computers, it was a different thing. Turns out a plugin works fine.
Thanks for the help.
:thumbup:
You're welcome...