-
Notifications
You must be signed in to change notification settings - Fork 130
Items Text_Cmd
ggodart edited this page Jan 6, 2021
·
1 revision
See original
Create a widget for inputting text commands
$Text_Input = new Generic_Item; &tk_entry("Text Input", $Text_Input, "tcmd1", $tcmd1);
if ($state = state_now $Text_Input) {
my $set_by = get_set_by $Text_Input;
print_log "Text_Input set_by $set_by typed $state";
run_voice_cmd($state, undef, $set_by);
}
Create commands
$tcmd1 = new Text_Cmd('hi (a|b|c)'); $tcmd2 = new Text_Cmd('bye *(.*)'); $tcmd3 = new Text_Cmd('(hi.*) (bye.*)');
Fire events if the commands match text input
$tcmd1->tie_event('print_log "tcmd1 state: $state"');
print_log "tcmd2 state=$state" if $state = state_now $tcmd2;
print_log "tcmd3 state=$state set_by=$tcmd3->{set_by}, target=$tcmd3->{target}" if $state = state_now $tcmd3;
Use this object if you want to fire events based on text entered. Unlike the Voice_Cmd
item, you can use Text_Cmd
to capture arbitrary text, using a regular expression.
Like Voice_Cmd
items, all text passed to the run_voice_cmd
and process_external_command
functions will be tested against all Text_Cmd
items. All items that match will fire their state_now
methods.
Method | Description |
---|---|
new($re_string) |
$re_string - is any valid regular expression. Use the () grouping to pick the data that will be returned with the state_now method. |
Method | Description |
---|---|
state |
Returns the text from the () match in the $re_string . If there was not () grouping, it returns 1. If there is more than one () grouping, the resulting matches are concatenated together with | as a separator. |
state_now |
Returns the state that was received or sent in the current pass. |