It is currently April 25th, 2024, 12:34 pm

[SOLVED] Lua, dinamyc variables and UpdateMeasure

Discuss the use of Lua in Script measures.
Caronte
Posts: 4
Joined: April 14th, 2011, 7:42 pm

[SOLVED] Lua, dinamyc variables and UpdateMeasure

Post by Caronte »

Hi,

First of all I would like to say thx for this great piece of software.

Now the question

Since I got my hands on Rainmeter I had the idea of creating a Profile skin for my G19 Keyboard. I have tons of profiles and is not that easy to remeber what goes where, so I messed around with the app and did some skins to get used to it.

Since I had no clue about lua I used your links to manuals, lua skins, etc.

Now i'm stuck on something quite stupid but just cant figure how to solve it.

Code: Select all

[MeasureProfiles]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url="file://C:\Users\caronte\AppData\Local\Logitech\G-series Software\Keyboard\Profiles\{F1584FF0-AC67-40D5-B1BC-3F0347083B4D}.lgp"
RegExp="(.*)"
Debug=2
Debug2File=#CURRENTPATH#profiles.txt
UpdateRate=55
FinishAction=!RainmeterEnableMeasure g19ProfilesXML #CURRENTCONFIG#


[g19ProfilesXML]
Measure=Script
ScriptFile="#CURRENTPATH#g19_profiles.lua"
TableName=g19_LUA_PROFILES
FileToParse="#CURRENTPATH#profiles.txt"
ShiftState=#MKey#
UpdateDivider=60
Disabled=1
DinamycVariables=1

[M3_key]
Meter=Image
ImageName=#M3_img#
X=250
Y=0
DinamycVariables=1
LeftMouseUpAction=!Execute [!RainmeterHideMeter M1_key_on][!RainmeterShowMeter M1_key][!RainmeterHideMeter M2_key_on][!RainmeterShowMeter M2_key][!RainmeterHideMeter M3_key][!RainmeterShowMeter M3_key_on][!RainmeterSetVariable Mkey 3][!RainmeterUpdateMeasure g19ProfilesXML #CURRENTCONFIG#][!RainmeterUpdateMeter Macro0 #CURRENTCONFIG#]
This is the code part that is killing me.

The first measure parses the whole xml profile and enables the lua script. There i grab the parts i need and show them (so far works perfectly), but since there are 3 posible configurations for the same keys on each profile (the key binding switches when u select the M1, M2 or M3 configuration) i want to be able to see the assigned keys for those Mkeys.

The variable update works like a charm but the Macros don't update.

I used a string meter to verfy that the Mkey variable updates and it does.

Either the lua script doesn't update or the Macros string don't do it.

PS: Just tryed with RainmeterUpdateMeterGroup but to no avail either.
Last edited by Caronte on April 15th, 2011, 6:45 am, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Lua, dinamyc variables and UpdateMeasure

Post by jsmorley »

The problem is that you can't send a "dynamic" variable to Lua in the script measure. Much like plugins, a script measure can't use dynamic variables, and so however it is defined initially in [Variables] is how it will stay.

So that's the bad news. The good news is that while you can't "pass" a variable to Lua that way in the script measure and have it update automatically, you CAN just use Lua to read the variable directly from Rainmeter.

If you put this in the "Update" function in Lua, so it is executed in each update of the script:

CurrentMKey = SKIN:ReplaceVariables("#MKey#")

Lua will ask Rainmeter for the current value of the variable, which you can then use any way you want.
Caronte
Posts: 4
Joined: April 14th, 2011, 7:42 pm

Re: Lua, dinamyc variables and UpdateMeasure

Post by Caronte »

And that did the trick right there.

Thx a lot.

Now the part I'm pretty sure it's not possible:

Can I capture the keys with a lua script?

That way I could make the Update process automatic and wont need to actually push the Mkey button.

Edit: Thx for the vocabulary correction, english is not my mother tongue as u might just noticed :D
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Lua, dinamyc variables and UpdateMeasure

Post by jsmorley »

I don't think so, not within the Rainmeter environment. Basic out of the box Lua is platform agnostic has very limited interaction with the operating system (can open / read / write files and execute calls to whatever is the standard shell (cmd.exe in the case of windows), but not much else. Lua can be extended with all kinds of external libraries, but that is not supported with Rainmeter yet. I don't know of any way to get Lua to detect the press of a key.
User avatar
santa_ryan
Posts: 397
Joined: June 22nd, 2010, 4:11 am

Re: Lua, dinamyc variables and UpdateMeasure

Post by santa_ryan »

While key detection cant be done with lua and rainmeter, it can be done with scripting programs such as AutoHotKey (and autoit).
Last edited by santa_ryan on May 9th, 2011, 5:15 am, edited 1 time in total.
I have three rules when I'm trying to help you.
  • Don't get mad when you don't understand something
  • Be VERY specific with what you ask for.
    The more specific you are, the higher the quality of support you receive.
  • Do not just copy and paste what I put in examples and come back saying it doesn't work.
    It does work, but I purposely left blanks that you need to fill for your specific needs.
Caronte
Posts: 4
Joined: April 14th, 2011, 7:42 pm

Re: Lua, dinamyc variables and UpdateMeasure

Post by Caronte »

Thx both.

I'll edit the subject and finish the skin to make it available to anyone.

Keep the great work with Rainmeter (i wish i had a linux version :D )