It is currently March 19th, 2024, 5:58 am

Working with InputText

Our most popular Tips and Tricks from the Rainmeter Team and others
Post Reply
User avatar
pul53dr1v3r
Posts: 442
Joined: July 30th, 2014, 10:30 am

Re: Working with InputText

Post by pul53dr1v3r »

is there a way to limit some words-strings to be entered in an InputText box?
User avatar
jsmorley
Developer
Posts: 22632
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Working with InputText

Post by jsmorley »

Pul53dr1v3r wrote: December 4th, 2019, 2:58 pm is there a way to limit some words-strings to be entered in an InputText box?
https://docs.rainmeter.net/manual/plugins/inputtext/#InputLimit
User avatar
pul53dr1v3r
Posts: 442
Joined: July 30th, 2014, 10:30 am

Re: Working with InputText

Post by pul53dr1v3r »

hi Morley. You misunderstood me thx to my mistake. Not to limit number of characters but to prohibit some strings to be entered no matter its length.
For example, i don't wan't that these strings are allowed to be a variable name (entered through InputText): jsmorley, pul53dr1v3r .

When i type them in, they shouldn't be accepted and written in the Variable.
Last edited by pul53dr1v3r on December 4th, 2019, 7:30 pm, edited 2 times in total.
User avatar
jsmorley
Developer
Posts: 22632
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Working with InputText

Post by jsmorley »

Pul53dr1v3r wrote: December 4th, 2019, 4:02 pm hi Morley. You misunderstood me thx to my mistake. Not to limit number of characters but to prohibit some strings to be entered no matter its length.
For example, i don't wan't that these strings are allowed to be a variable name (entered through InputText): jsmorley, pul53dr1v3r .

When i type them in, they should be accepted and written in the Variable.
Not easily. You can't limit what is allowed as a string "before the fact" in any way. I guess you could use an IfMatch on the InputText plugin measure that will evaluate what is entered "after the fact", and take some action, like setting a variable value to "" or "Not Allowed" or something else.
User avatar
balala
Rainmeter Sage
Posts: 16091
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Working with InputText

Post by balala »

EDIT: Sorry jsmorley...
Pul53dr1v3r wrote: December 4th, 2019, 4:02 pm hi Morley. You misunderstood me thx to my mistake. Not to limit number of characters but to prohibit some strings to be entered no matter its length.
For example, i don't wan't that these strings are allowed to be a variable name (entered through InputText): jsmorley, pul53dr1v3r .

When i type them in, they should be accepted and written in the Variable.
Probably such a possibility doesn't exist, however I suppose a String measure could help. You should transfere the entered string to a String measure and there an IfMatch options set could write or not the strings, depending on their value.
User avatar
jsmorley
Developer
Posts: 22632
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Working with InputText

Post by jsmorley »

This is about as close as I can see to get, and it's certainly not the same as "not allowing" some input. It's more "throwing away" disallowed input. You simply can't stop the input before the fact, and you can't have it keep the input active and insist that something else be entered.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]
MyVar=Starting Value

[MeterSearchBox]
Meter=Shape
Shape=Rectangle 1,1,202,25 | Fill Color 215,215,215,255 | Stroke Color 130,130,130,255
W=202
H=25

[MeterSearchLabel]
Meter=String
X=5
Y=4
W=200
H=23
SolidColor=0,0,0,1
FontColor=47,47,47,255
FontFace=Fira Sans
FontSize=12
AntiAlias=1
Text=Enter here
LeftMouseUpAction=[!EnableMeasure MeasureInput][!CommandMeasure "MeasureInput" "ExecuteBatch 1"]

[MeasureInput]
Measure=Plugin
Plugin=InputText
X=1
Y=2
W=200
H=22
SolidColor=200,200,200,255
FontColor=47,47,47,255
FontFace=Fira Sans
FontSize=11
AntiAlias=1
FocusDismiss=1
DynamicVariables=1
Disabled=1
UpdateDivider=-1
IfMatch=(?i)^jsmorley$|^pul53dr1v3r$
IfMatchAction=[Play error]
IfNotMatchAction=[!SetVariable MyVar "[MeasureInput]"]
Command1=[$UserInput$][!UpdateMeasure MeasureInput]
So if something "not allowed" is entered, it will just beep and throw away the result as soon as the user hits enter. If the text is "allowed", then a variable value is set.

You will need ONE line if IfMatch conditions, with the various text strings separated by a | logical OR symbol. Logic will not allow you to use multiple IfMatch[n] conditions, as the IfNotMatchAction[n] options will fight each other.
User avatar
pul53dr1v3r
Posts: 442
Joined: July 30th, 2014, 10:30 am

Re: Working with InputText

Post by pul53dr1v3r »

Pul53dr1v3r wrote: December 4th, 2019, 4:02 pm When i type them in, they should be accepted and written in the Variable.

:jawdrop
@morley, balala
Sorry once again. I meant "When i type them in, they shouldn't be accepted and written in Variable." but you got my intention.
jsmorley wrote: December 4th, 2019, 6:25 pm
Perfect solution! :Ok

I just had to add 2 more things in the code to get the example completely works:
1. [!WriteKeyValue... to IfNotMatchAction action, since the variable had not been changed for me using only SetVariable,
2. Command2=[!RefreshGroup "Test"], because the sound wouldn't play if 2 or more prohibited values are entered in a session.

:rosegift:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
Group=Test

[Variables]
MyVar=55555

[MeterSearchBox]
Meter=Shape
Shape=Rectangle 1,1,202,25 | Fill Color 215,215,215,255 | Stroke Color 130,130,130,255
W=202
H=25

[MeterSearchLabel]
Meter=String
X=5
Y=4
W=200
H=23
SolidColor=0,0,0,1
FontColor=47,47,47,255
FontFace=Fira Sans
FontSize=12
AntiAlias=1
Text=Enter here
LeftMouseUpAction=[!EnableMeasure MeasureInput][!CommandMeasure "MeasureInput" "ExecuteBatch 1-2"]

[MeasureInput]
Measure=Plugin
Plugin=InputText
X=1
Y=2
W=200
H=22
SolidColor=200,200,200,255
FontColor=47,47,47,255
FontFace=Fira Sans
FontSize=11
AntiAlias=1
FocusDismiss=1
DynamicVariables=1
Disabled=1
UpdateDivider=-1
IfMatch=(?i)^jsmorley$|^pul53dr1v3r$
IfMatchAction=[Play error]
IfNotMatchAction=[!WriteKeyValue Variables MyVar "[MeasureInput]"][!SetVariable MyVar "[MeasureInput]"]
Command1=[$UserInput$][!UpdateMeasure MeasureInput]
Command2=[!RefreshGroup "Test"]
User avatar
pul53dr1v3r
Posts: 442
Joined: July 30th, 2014, 10:30 am

Re: Working with InputText

Post by pul53dr1v3r »

if a forbidden string is language tag, for example en-GB, how to prevent opening Windows language folder (C:\Windows\System32\en-GB) whenever i enter the tag in the InbutText box?
User avatar
jsmorley
Developer
Posts: 22632
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Working with InputText

Post by jsmorley »

Pul53dr1v3r wrote: December 4th, 2019, 11:00 pm if a forbidden string is language tag, for example en-GB, how to prevent opening Windows language folder (C:\Windows\System32\en-GB) whenever i enter the tag in the InbutText box?
I don't follow that a bit.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5364
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA
Contact:

Re: Working with InputText

Post by eclectic-tech »

Pul53dr1v3r wrote: December 4th, 2019, 11:00 pm if a forbidden string is language tag, for example en-GB, how to prevent opening Windows language folder (C:\Windows\System32\en-GB) whenever i enter the tag in the InbutText box?
Even though the $UserInput$ matches a forbidden text, the [MeasureInput] batch commands are still going to be executed...

I would suggest writing the $UserInput$ to #MyVar# no matter what it is and creating a separate measure to test and take actions based on those results (as suggested by balala).

This will not execute the $UserInput$ if it matches one of the "forbidden text" and will set #MyVar# to "" if it does.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
Group=Test

[Variables]
MyVar=55555

[MeterSearchBox]
Meter=Shape
Shape=Rectangle 1,1,202,25 | Fill Color 215,215,215,255 | Stroke Color 130,130,130,255
W=202
H=25

[MeterSearchLabel]
Meter=String
X=5
Y=4
W=200
H=23
SolidColor=0,0,0,1
FontColor=47,47,47,255
FontFace=Fira Sans
FontSize=12
AntiAlias=1
Text=Enter here
LeftMouseUpAction=[!EnableMeasure MeasureInput][!CommandMeasure "MeasureInput" "ExecuteBatch 1"]

[MeasureInput]
Measure=Plugin
Plugin=InputText
X=1
Y=2
W=200
H=22
SolidColor=200,200,200,255
FontColor=47,47,47,255
FontFace=Fira Sans
FontSize=11
AntiAlias=1
FocusDismiss=1
DynamicVariables=1
Disabled=1
UpdateDivider=-1
Command1=[!WriteKeyValue Variables MyVar "$UserInput$"][!SetVariable MyVar "[MeasureInput]"][!EnableMeasure MeasureInputAction][!UpdateMeasure MeasureInputAction]
;Command2=[!RefreshGroup "Test"]

[MeasureInputAction]
DynamicVariables=1
Measure=String
String=#MyVar#
IfMatch=(?i)^jsmorley$|^pul53dr1v3r$|^en-gb$
IfMatchAction=[!DisableMeasure MeasureInput][!WriteKeyValue Variables MyVar ""][Play error]
IfNotMatchAction=["#MyVar#"][!RefreshGroup "Test"]
Disabled=1

Post Reply