Author Topic: enabling/disabling commands  (Read 1395 times)

Squeeze

  • Newbie
  • *
  • Posts: 25
enabling/disabling commands
« on: May 25, 2021, 04:09:55 AM »
I need to deactivate and activate commands from my profile. How can i do this? What is SetSessionEnabled() and GetSessionEnabled() exactly do? (they are not mentioned in the help file). I need to deactivate/enable execution of commands somehow. Please answer with some short example code! Thanks!

Squeeze

  • Newbie
  • *
  • Posts: 25
Re: enabling/disabling commands
« Reply #1 on: May 25, 2021, 04:53:27 AM »
and i have another problem which i'm trying to circumvent: I want to disable commands if a Bool is set to true. So i used a condition builder inside each command to execute my actions only if the Bool State is true. The problem is that i set some commands to block passthrough of the keyboard key but the key should only be blocked when the Bool State is true. Right now it always blocks passtrough. Is there a way to prevent this?

Squeeze

  • Newbie
  • *
  • Posts: 25
Re: enabling/disabling commands
« Reply #2 on: May 25, 2021, 11:08:07 AM »
problem solved (by using if conditions in my profile).

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2827
Re: enabling/disabling commands
« Reply #3 on: May 25, 2021, 11:11:52 AM »
Awesome to hear - glad you got it up and running!

Were you able to finally find the Get/SetSessionEnabled() info in the help doc?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4757
  • RTFM
Re: enabling/disabling commands
« Reply #4 on: May 25, 2021, 11:18:50 AM »
While the effects of the "Do not allow key to be passed through" option cannot be changed dynamically, as mentioned before, you can partially work around that by having VoiceAttack send the keypress for you instead, as part of the command, which I'll assume is what you've already done at this point.


Those methods don't require anything special in your inline function, not even the default includes. You do need to specify the classes that method can be found in, so the compiler can look for them.

E.G.
Code: [Select]
public class VAInline
{
public void main()
{
VA.Command.SetSessionEnabled("my command", false);
}
}
to disable "my command" (this also disables any other command phrases linked to the command, it's just used at the identifier to find the command you're referencing)

Code: [Select]
public class VAInline
{
public void main()
{
VA.Command.SetSessionEnabled("my command", true);
}
}
to enable "my command" again

If you want to check whether a command is disabled, that can be done using something like
Code: [Select]
public class VAInline
{
public void main()
{
VA.SetBoolean("my Boolean variable name", VA.Command.GetSessionEnabled("my command"));
}
}
which should set the Boolean variable "my Boolean variable name", to "true" if the command is enabled (the default state), or "false" is disabled


Do note that all of this is advanced functionality. If you intend to use inline functions, you'll want to learn at least the basics of C#/.NET, and keep in mind that there are much fewer protections (E.G. you can easily set up an infinite loop that uses up all the CPU time it can)