It is currently March 28th, 2024, 6:05 pm

[SOLVED] How to bring skin(s) to front with keyboard shortcut?

Get help with installing and using Rainmeter.
Post Reply
WirlyWirly
Posts: 17
Joined: July 15th, 2020, 6:37 am

[SOLVED] How to bring skin(s) to front with keyboard shortcut?

Post by WirlyWirly »

I'm looking for a way to bring my skin(s) to the front when I press ctrl+space, and then return them to the desktop after a single click, be it on or off a skin.

If not, then maybe a "while ctrl+space" method that keeps the skins on-top until I release the defined keys. A toggle would be last on the preference, but I wouldn't rule it out.

I'm essentially trying to get more use out of my skins, which won't happen if I have to minimize all my windows to get to them. I also don't want to be accidentally activating them when I hover my mouse to predefined areas, so anything on-screen is out.

I'm fairly new to rainmeter, but after modifying a skin, I'm more comfortable with the syntax. I'm thinking I'll have to use the !ZPos bang to get this to work, but I can't figure out how to have rainmeter monitor for keystrokes. I'd prefer not to use any external programs such as AutoHotKey, since I'm trying to keep the whole skin portable, but if that's necessary then let me know.
Last edited by WirlyWirly on July 15th, 2020, 10:16 pm, edited 3 times in total.
User avatar
Jeff
Posts: 326
Joined: September 3rd, 2018, 11:18 am

Re: How to bring skin(s) to front with keyboard shortcut?

Post by Jeff »

HotKey Plugin

Code: Select all

[Rainmeter]
LeftMouseUpAction=!ZPos "-2"

[HotKey]
Measure=Plugin
Plugin=HotKey
HotKey=CTRL SPACE
KeyDownAction=!ZPos "2"
Obviously you'll modify what position it goes to, if you want the action to be done when you hold the keys down or release them, or if you want the skin to go back when you click a meter instead of anywhere on the skin (that's why the [Rainmeter] section there), etc. Just have fun.
WirlyWirly
Posts: 17
Joined: July 15th, 2020, 6:37 am

Re: How to bring skin(s) to front with keyboard shortcut?

Post by WirlyWirly »

Thanks for the code snippet! I was able to get the main functionality working, just trying to buffer out a couple quality of life issues...
  • triggering [!Zpos "-2"] when clicking outside of a skin: At the moment, I have to click either on a meter or a part of the skin to activate the [!ZPos "-2"] action.
  • Triggering [!Zpos "-2"] on all skins simultaneously: I currently have 2 skins (A and B). When I make a selection on skin A, [!Zpos "-2"] is triggerd. However, skin B remains and I have to also make a selection on it for the ZPos action. Looking for a way to have them all hide at once. Perhaps with some type of global variable that gets updated across skins?


Here's how my code is looking on one of my skins...

Code: Select all

[RainMeter]
Update = 1000
AccurateText = 1
BackgroundMode = 2
SolidColor = 0,0,0,1
DynamicWindowSize = 1
LeftMouseUpAction = [!ZPos "-2"]

--- snip ---

[DisplayFront]
Measure = Plugin
Plugin = HotKey
HotKey = CTRL SPACE
KeyUpAction = [!ZPos "1"]


--- snip ---

[MeterGitBash]
Meter = Image
...
LeftMouseUpAction = ["#PROGRAMDRIVE#\#portableapps_apps#\PortableGit\git-bash.exe"][!ZPos "-2"]

User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to bring skin(s) to front with keyboard shortcut?

Post by balala »

WirlyWirly wrote: July 15th, 2020, 4:38 pm
  • triggering [!Zpos "-2"] when clicking outside of a skin: At the moment, I have to click either on a meter or a part of the skin to activate the [!ZPos "-2"] action.
To get when you click outside of a skin, you can add an OnUnfocusAction option to its [Rainmeter] section. The bangs of this option are executed when the skin which has this option, looses the focus.
WirlyWirly wrote: July 15th, 2020, 4:38 pm
  • Triggering [!Zpos "-2"] on all skins simultaneously: I currently have 2 skins (A and B). When I make a selection on skin A, [!Zpos "-2"] is triggerd. However, skin B remains and I have to also make a selection on it for the ZPos action. Looking for a way to have them all hide at once. Perhaps with some type of global variable that gets updated across skins?
I'd add two variables to any of the two skins, which are registering when one or the other skin is focused or lost the focus. For instance add the following two variables to Skin A:

Code: Select all

[Variables]
...
ZPosSkinA=1
ZPosSkinB=1
(if the code has other variables as well, don't remove or modify them, just add these ones).
Now add the following options to the [Rainmeter] section of both skins:
  • Skin A:

    Code: Select all

    [Rainmeter]
    ...
    OnUnfocusAction=[!SetVariable ZPosSkinA "0"][!UpdateMeasure "MeasureZPos"]
  • Skin B:

    Code: Select all

    [Rainmeter]
    ...
    OnUnfocusAction=[!SetVariable ZPosSkinB "0" "ConfigOfSkinA"][!UpdateMeasure "MeasureZPos" "ConfigOfSkinA"]
Note the new parameters on both bangs added to Skin B: "ConfigOfSkinA". Replace ConfigOfSkinA with real name of the config of Skin A (if you don't know what is it, please post a question, to explain). This parameter sets the variable on Skin A and updates the [MeasureZPos] measure of Skin A. This is important, because Skin B won't have a [MeasureZPos] measure, which (will) exist(s) only on Skin A. Also be careful that in the last OnUnfocusAction option I set the ZPosSkinB variable, but in Skin A, so the last parameter is the config of skin A (ConfigOfSkinA). This is not a mistake.
Add the following measure to Skin A:

Code: Select all

[MeasureZPos]
Measure=Calc
Formula=( #ZPosSkinA# + #ZPosSkinB# )
IfCondition=(#CURRENTSECTION#=2)
IfTrueAction=[!ZPos "2"][!ZPos "2" "ConfigOfSkinB"]
IfFalseAction=[!ZPos "0"][!ZPos "0" "ConfigOfSkinB"]
DynamicVariables=1
Note that this time the last parameter of the second !ZPos bangs is ConfigOfSkinB, not ConfigOfSkinA, as it was on the OnUnfocusAction option added to the [Rainmeter] section of Skin B.
Finally you have to modify the KeyDownAction option of the [HotKey] measure: KeyDownAction=[!SetVariable ZPosSkinA "1"][!SetVariable ZPosSkinB "1"][!UpdateMeasure "MeasureZPos"] (here I supposed the [MeasureZPos] measure is added to Skin A, not to Skin B - if it's on Skin B, move it to Skin A).
WirlyWirly
Posts: 17
Joined: July 15th, 2020, 6:37 am

Re: How to bring skin(s) to front with keyboard shortcut?

Post by WirlyWirly »

Thanks a bunch balala! I didn't expect there to be built-in way to change change variables, z-positions, and call functions across .ini files. Lots of very neat and useful trick in your code snippet.

One thing though is that !ZPos does not seem to give focus, it only brings skins to the front while focus remains on the previous window. Therefore the OnUnfocusAction= options weren't working since the skin never had focus to begin with.

I was able to utilize StealFocus.exe to bring skin A into focus, which allowed me to get the rest of your code working. I found no built-in way of giving a skin focus, but if there is I'd love to hear about it.

After seeing how your code works, I simplified it somewhat and I believe I have all the functionality I was looking for; Toggle all skins to the the front with ctrl+Space, then returns all skins to the desktop after clicking on a meter, skin, or outside of a skin.

I use portableapps, which has a very basic launcher. Using rainmeter as my main launcher is going to be life-changing. The base skin is StickyBar by ninjaki8, but I've modified it heavily to fit my preferences.
Image

Here's my code for anyone that is also interested in setting up something like this.

Code: Select all

[RainMeter]
...
LeftMouseUpAction = "#skins_bottom#"
OnUnfocusAction = "#skins_bottom#"

[Variables]
...
skins_top = [!ZPos "1"][!ZPos "1" "StickyBar\Recycle"][!ZPos "1" "StickyBar\Date"]["#@#StealFocus.exe" "#CURRENTPATH##CURRENTFILE#"]
skins_bottom = [!ZPos "-2"][!ZPos "-2" "StickyBar\Date"][!ZPos "0" "StickyBar\Recycle"]

[DisplayFront]
Measure = Plugin
Plugin = HotKey
HotKey = CTRL SPACE
KeyUpAction = "#skins_top#"

--- snip ---

[MeterGitBash]
...
LeftMouseUpAction = ["#PROGRAMPATH#..\PortableGit\git-bash.exe"]["#skins_bottom#"]

--- snip ---
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to bring skin(s) to front with keyboard shortcut?

Post by balala »

WirlyWirly wrote: July 15th, 2020, 8:52 pm Lots of very neat and useful trick in your code snippet.
Thank you.
WirlyWirly wrote: July 15th, 2020, 8:52 pm One thing though is that !ZPos does not seem to give focus, it only brings skins to the front while focus remains on the previous window. Therefore the OnUnfocusAction= options weren't working since the skin never had focus to begin with.
Right. !ZPos doesn't give focus.
WirlyWirly wrote: July 15th, 2020, 8:52 pm I was able to utilize StealFocus.exe to bring skin A into focus, which allowed me to get the rest of your code working. I found no built-in way of giving a skin focus, but if there is I'd love to hear about it.
Right, there is no such built-in way. Beside jsmorley's StealFocus, a while ago another similar app has been posted by ~Faradey~. I didn't try RainFocus, but maybe it worth a try, if you are interested.
Post Reply