It is currently October 15th, 2024, 12:11 am

HotKey plugin 1.0

Plugins and Addons popular with the Community
Devo
Posts: 8
Joined: May 1st, 2020, 8:17 pm

Re: HotKey plugin 1.0

Post by Devo »

balala wrote: October 19th, 2021, 5:50 pm Ok, here is it. Add the IfCondition / IfTrueAction / IfFalseAction options to the [MeasurePlayPause] measure, without modifying it otherwise. The two !SetOption bangs will set the appropriate KeyDownAction option to the [HideSkins] measure:

Code: Select all

[MeasurePlayPause]
...
IfCondition=(MeasurePlayPause=2)
IfTrueAction=[!SetOption HideSkins KeyDownAction """[!Hide *][!CommandMeasure "MeasureMedia" "PlayPause"][!CommandMeasure "MeasureMedia" "VolumeMute"]"""][!UpdateMeasure "HideSkins"]
IfFalseAction=[!SetOption HideSkins KeyDownAction """[!Hide *][!CommandMeasure "MeasureMedia" "VolumeMute"]"""][!UpdateMeasure "HideSkins"]
Additionally you can freely remove the KeyDownAction option of the [HideSkins] measure, because this option is now set dynamically by one of the above !SetOption bangs, so there is no need to have it explicitly set on the measure. It's not a problem is you leave it there, but it's completely useless, because on refresh of the skin, it is anyway set by one of the above bangs.

Take care that the !Hide (used by you above) and the !Hide * (used by Devo, in the !RainmeterHide * form), perform different actions. First is hiding the current skin, while the last is hiding ALL activated skins.
For some reason your method isn't working properly. The goal is to hide all skins, mute the system volume, and pause any playing music. What's happening is that some of the skins are hidden, the volume is muted, and the music keeps playing. I like you code better because it's more simple, but I might have to stick with death.crafter's because it is working as intended. I've cobbled together a couple different pieces of code so maybe there's a bug in the way I put it together. Below is the full code for both options;

balala's code

Code: Select all

[Rainmeter]
Update=1000
BackgroundMode=2

[Variables]
HideKey=CTRL BACKSLASH
ShowKey=CTRL RBRACKET

[MeasureMedia]
Measure=MediaKey

;The play state of the player
;0 is no song is selected, this will almost never happen as the plugin retains the last known song in the future I may change it so it clears when the websocket closes but I dont think I want to do that in the event the websocket closes unexpectedly you may want it to keep old data
;1 is playing
;2 is paused
[MeasurePlayPause]
Measure=Plugin
Plugin=WebNowPlaying
PlayerType=State
IfCondition=(MeasurePlayPause=1)
IfTrueAction=[!SetOption HideSkins KeyDownAction """[!RainmeterHide *][!CommandMeasure "MeasureMedia" "PlayPause"][!CommandMeasure "MeasureMedia" "VolumeMute"]"""][!UpdateMeasure "HideSkins"]
IfFalseAction=[!SetOption HideSkins KeyDownAction """[!RainmeterHide *][!CommandMeasure "MeasureMedia" "VolumeMute"]"""][!UpdateMeasure "HideSkins"]

[Meter]
Meter=String
Text=""

[HideSkins]
Measure=Plugin
Plugin=HotKey
HotKey=#HideKey#

[ShowSkins]
Measure=Plugin
Plugin=HotKey
HotKey=#ShowKey#
KeyDownAction=[!RainmeterShow *]

death.crafter's code:

Code: Select all

[Rainmeter]
Update=1000
BackgroundMode=2

[Variables]
HideKey=CTRL BACKSLASH
ShowKey=CTRL RBRACKET
HideSkins0=[!RainmeterHide *][!CommandMeasure "MeasureMedia" "VolumeMute"]
HideSkins1=[!RainmeterHide *][!CommandMeasure "MeasurePlayPause" "PlayPause"][!CommandMeasure "MeasureMedia" "VolumeMute"]

[MeasureMedia]
Measure=MediaKey

;The play state of the player
;0 is no song is selected, this will almost never happen as the plugin retains the last known song in the future I may change it so it clears when the websocket closes but I dont think I want to do that in the event the websocket closes unexpectedly you may want it to keep old data
;1 is playing
;2 is paused
[MeasurePlayPause]
Measure=Plugin
Plugin=WebNowPlaying
PlayerType=State

[IsPlaying]
Measure=Calc
Formula=MeasurePlayPause = 1

[Meter]
Meter=String
Text=""

[HideSkins]
Measure=Plugin
Plugin=HotKey
HotKey=#HideKey#
KeyDownAction=[#HideSkins[&IsPlaying]]

[ShowSkins]
Measure=Plugin
Plugin=HotKey
HotKey=#ShowKey#
KeyDownAction=[!RainmeterShow *]
User avatar
balala
Rainmeter Sage
Posts: 16658
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: HotKey plugin 1.0

Post by balala »

death.crafter wrote: October 19th, 2021, 6:09 pm Ahh right, didn't notice. Thanks for letting me know!
Don't worry, it happens to all of us to miss such detail :thumbup:
Devo
Posts: 8
Joined: May 1st, 2020, 8:17 pm

Re: HotKey plugin 1.0

Post by Devo »

Also, while I have your attention, I'm using WebNowPlaying to play/pause music because I generally play through my browser, but is there a more global function/plugin I should be using that will play/pause any media playing through Windows?
User avatar
death.crafter
Rainmeter Sage
Posts: 1398
Joined: April 24th, 2021, 8:13 pm

Re: HotKey plugin 1.0

Post by death.crafter »

Devo wrote: October 19th, 2021, 6:15 pm Also, while I have your attention, I'm using WebNowPlaying to play/pause music because I generally play through my browser, but is there a more global function/plugin I should be using that will play/pause any media playing through Windows?
https://docs.rainmeter.net/manual/measures/mediakey/
from the Realm of Death
User avatar
balala
Rainmeter Sage
Posts: 16658
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: HotKey plugin 1.0

Post by balala »

Devo wrote: October 19th, 2021, 6:13 pm For some reason your method isn't working properly. The goal is to hide all skins, mute the system volume, and pause any playing music. What's happening is that some of the skins are hidden, the volume is muted, and the music keeps playing. I like you code better because it's more simple, but I might have to stick with death.crafter's because it is working as intended. I've cobbled together a couple different pieces of code so maybe there's a bug in the way I put it together. Below is the full code for both options;
Right, now I see why. Unfortunately a small mistake crept into the code. To my excuse I didn't know about this small detail and noticed it only now.
You have to explicitly set a KeyDownAction option on the HotKey plugin bang, even if you change it through !Setoption bang. Yes, I said in my previous reply that:
balala wrote: October 19th, 2021, 5:50 pm Additionally you can freely remove the KeyDownAction option of the [HideSkins] measure, because this option is now set dynamically by one of the above !SetOption bangs, so there is no need to have it explicitly set on the measure.
But this it seems proved to not be true. You either have to leave the KeyDownAction option there or you can add any option, but have to add one. For instance leave the previously existing option or if you removed it add something simple like KeyDownAction=[!Delay "1000"] (this doesn't perform any de facto action, it is there just for what has been described above).
My bad didn't know about this small detail. Sorry I misled you. Please let me know if this fixed the issue.
User avatar
death.crafter
Rainmeter Sage
Posts: 1398
Joined: April 24th, 2021, 8:13 pm

Re: HotKey plugin 1.0

Post by death.crafter »

balala wrote: October 19th, 2021, 7:14 pm But this it seems proved to not be true. You either have to leave the KeyDownAction option there or you can add any option, but have to add one. For instance leave the previously existing option or if you removed it add something simple like KeyDownAction=[!Delay "1000"] (this doesn't perform any de facto action, it is there just for what has been described above).
My bad didn't know about this small detail. Sorry I misled you. Please let me know if this fixed the issue.
Actually it is true. You don't need to have the option explicitly present to use !SetOption.

But in my opinion, you are overcomplicating it using IfConditions and stuff.

To OP:

Code: Select all

[Variables]
HideKey=CTRL BACKSLASH
ShowKey=CTRL RBRACKET
HideSkins0=[!Hide *][!CommandMeasure "MeasureMedia" "VolumeMute"]
HideSkins1=[!Hide *][!CommandMeasure "MeasurePlayPause" "PlayPause"][!CommandMeasure "MeasureMedia" "VolumeMute"]

[MeasurePlayPause]
Measure=Plugin
Plugin=WebNowPlaying
PlayerType=State
Substitute="2":"0"

[HideSkins]
Measure=Plugin
Plugin=HotKey
HotKey=#HideKey#
KeyDownAction=[!UpdateMeasure PlayPause][#HideSkins[&MeasurePlayPause]]

[ShowSkins]
Measure=Plugin
Plugin=HotKey
HotKey=#ShowKey#
KeyDownAction=[!Show *]
I think this will be easier since there is no extra measure. And also notice that I am updating the measure before executing the bang, so the state will be updated before action is executed, so you have less chance of the wrong action getting executed, saying cause WNP is a little slow. Also Update is 1000.
from the Realm of Death
Devo
Posts: 8
Joined: May 1st, 2020, 8:17 pm

Re: HotKey plugin 1.0

Post by Devo »

death.crafter wrote: October 20th, 2021, 3:32 am Actually it is true. You don't need to have the option explicitly present to use !SetOption.

But in my opinion, you are overcomplicating it using IfConditions and stuff.

To OP:

Code: Select all

[Variables]
HideKey=CTRL BACKSLASH
ShowKey=CTRL RBRACKET
HideSkins0=[!Hide *][!CommandMeasure "MeasureMedia" "VolumeMute"]
HideSkins1=[!Hide *][!CommandMeasure "MeasurePlayPause" "PlayPause"][!CommandMeasure "MeasureMedia" "VolumeMute"]

[MeasurePlayPause]
Measure=Plugin
Plugin=WebNowPlaying
PlayerType=State
Substitute="2":"0"

[HideSkins]
Measure=Plugin
Plugin=HotKey
HotKey=#HideKey#
KeyDownAction=[!UpdateMeasure PlayPause][#HideSkins[&MeasurePlayPause]]

[ShowSkins]
Measure=Plugin
Plugin=HotKey
HotKey=#ShowKey#
KeyDownAction=[!Show *]
I think this will be easier since there is no extra measure. And also notice that I am updating the measure before executing the bang, so the state will be updated before action is executed, so you have less chance of the wrong action getting executed, saying cause WNP is a little slow. Also Update is 1000.
Thanks for the help, I think I've got it in about it's final form. A couple things to note:
  • You need both MediaKeys and WebNowPlaying plugins. MediaKeys controls the volume but can't control the play/pause button and WebNowPlaying controls the play/pause button but can't control the volume. I tried using NowPlaying instead of WebNowPlaying, but I can't seem to get it to work. I'm running the latest version of Rainmeter.
  • You also need a dummy meter so Rainmeter doesn't automatically deactivate the skin.
I have included the final version of the skin below, if you can see any further improvements please let me know. Thanks for all your help.

Code: Select all

[Rainmeter]
Update=1000
BackgroundMode=2

[Variables]
HideKey=CTRL BACKSLASH
ShowKey=CTRL RBRACKET
HideSkins0=[!RainmeterHide *][!CommandMeasure "MeasureMediaKey" "VolumeMute"]
HideSkins1=[!RainmeterHide *][!CommandMeasure "MeasureMediaKey" "VolumeMute"][!CommandMeasure "MeasurePlayPause" "PlayPause"]

[MeasureMediaKey]
Measure=MediaKey

[MeasurePlayPause]
;The play state of the player
;0 is no song is selected
;1 is playing
;2 is paused
;3 is replay
Measure=Plugin
Plugin=WebNowPlaying
PlayerType=State
Substitute="2":"0", "3":"0"

[Meter]
;Dummy meter so the skin doesn't get automatically deactivated by Rainmeter
Meter=String
Text=""

[HideSkins]
Measure=Plugin
Plugin=HotKey
HotKey=#HideKey#
KeyDownAction=[!Update MeasurePlayPause][#HideSkins[&MeasurePlayPause]]

[ShowSkins]
Measure=Plugin
Plugin=HotKey
HotKey=#ShowKey#
KeyDownAction=[!RainmeterShow *]
User avatar
balala
Rainmeter Sage
Posts: 16658
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: HotKey plugin 1.0

Post by balala »

death.crafter wrote: October 20th, 2021, 3:32 am Actually it is true. You don't need to have the option explicitly present to use !SetOption.
Actually it's not.
Have you tried? Just asking, because if any KeyDownAction option is set explicitly on the measure, it can be easily modified through a !SetOption bang. But if it's not, you can try to apply any KeyDownAction option through any kind of !SetOption bang, it anyway won't work. I know doesn't make too much sense and can't explain this. It definitely should work if you apply a proper KeyDownAction option with a !SetOption bang, no matter if there is or isn't set an explicit option. However it seems it doesn't.
Example: see the following extremely simple code:

Code: Select all

[Rainmeter]
Update=1000
OnRefreshAction=[!SetOption MeasureAdd KeyDownAction """[!UpdateMeasure "MyMeasure"][!UpdateMeter "MeterShow"][!Redraw]"""]

[MyMeasure]
Measure=Calc
Formula=( MyMeasure + 1 )
UpdateDivider=-1

[MeasureAdd]
Measure=Plugin
Plugin=HotKey
HotKey=Q
DynamicVariables=1

[MeterShow]
Meter=STRING
MeasureName=MyMeasure
X=0
Y=0
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=%1
DynamicVariables=1
As you can see the [MeasureAdd] HotKey plugin measure doesn't have set a KeyDownAction option. The OnRefreshAction of the [Rainmeter] section should apply a simple such option, which will update the [MyMeasure] measure, increasing the value by one. But it doesn't.
To get this working you have to add any KeyDownAction option to the [MeasureAdd] measure. For instance something like KeyDownAction=[!Delay "1000"] (or whatever else). When this option is explicitly set, the measure will be incremented by hitting the Q key, accordingly to what is set by the OnRefreshAction option.
QED...
death.crafter wrote: October 20th, 2021, 3:32 am I think this will be easier since there is no extra measure. And also notice that I am updating the measure before executing the bang, so the state will be updated before action is executed, so you have less chance of the wrong action getting executed, saying cause WNP is a little slow. Also Update is 1000.
There is no extra measure in my code either. But finally doesn't matter too much. Which solution is preferred by a user depends by more things. I didn't say your solution is not good, there is nothing wrong with it. But when Devo said that:
Devo wrote: October 19th, 2021, 3:27 pm That's correct. @death.crafter's solution works, but I'm wondering if there's a more elegant(?) or simpler solution.
I came with the !SetOption solution. As usually there are more solutions to the same question. Your is one of them, mine is another. None better, none worse...
User avatar
death.crafter
Rainmeter Sage
Posts: 1398
Joined: April 24th, 2021, 8:13 pm

Re: HotKey plugin 1.0

Post by death.crafter »

Devo wrote: October 20th, 2021, 5:25 pm Thanks for the help, I think I've got it in about it's final form. A couple things to note:
  • You need both MediaKeys and WebNowPlaying plugins. MediaKeys controls the volume but can't control the play/pause button and WebNowPlaying controls the play/pause button but can't control the volume. I tried using NowPlaying instead of WebNowPlaying, but I can't seem to get it to work. I'm running the latest version of Rainmeter.
  • You also need a dummy meter so Rainmeter doesn't automatically deactivate the skin.
Ahh no, I just listed the relevant things.

Also !RainmeterHide is deprecated. Just use !Hide instead.
from the Realm of Death
User avatar
balala
Rainmeter Sage
Posts: 16658
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: HotKey plugin 1.0

Post by balala »

Devo wrote: October 20th, 2021, 5:25 pm Thanks for the help, I think I've got it in about it's final form.
Obviously you can use any solution you like more, however I'm not entirely sure you didn't miss my post, which explains why my code didn't work.