Author Topic: How to detect keypress from another profile?  (Read 1624 times)

Starblue7

  • Full Member
  • ***
  • Posts: 131
How to detect keypress from another profile?
« on: May 07, 2023, 07:38:20 AM »
Profile #1 - Is the loaded profile and a verbal command kicks off a command in that profile which presses a key.

Profile #2 - Its commands are included in Profile #1 via the Profile Options / Include Commands from other profiles.

Profile #2 - Needs to know if Profile #1 actually hit a key.

One could put up some polling loop command in Profile #2 and do something like:

Code: [Select]
    Begin Condition : (Keyboard Key 'F7' Is Pressed)
        Then do something....
    End Condition

But that doesn't seem to work, as it won't intercept any keypresses Profile #1 is doing.
« Last Edit: May 08, 2023, 05:31:00 AM by Starblue7 »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: How to detect keypress from another profile?
« Reply #1 on: May 07, 2023, 11:07:29 AM »
VoiceAttack specifically ignores keypresses it produces itself. This is intended behavior.

Starblue7

  • Full Member
  • ***
  • Posts: 131
Re: How to detect keypress from another profile?
« Reply #2 on: May 07, 2023, 04:30:23 PM »
Thanks.  Ok.  OoTB intended functionality.
Though could you offer any creative ways to tackle this without relying an another application?
Thanks
Thanks

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: How to detect keypress from another profile?
« Reply #3 on: May 07, 2023, 04:44:55 PM »
I misinterpreted what you were initially saying as wanting to trigger a command based on a keypress from another command.

If you're using either the "Device State" tab, or the "{STATE_KEYSTATE:}" token, that should return the state of a given key including when it's pressed by VoiceAttack itself.


If you're using a loop, especially one containing a lot of actions, it may just be missing the press (I.E. it's checking before or after the command begins pressing or has already released the key, respectively)

Starblue7

  • Full Member
  • ***
  • Posts: 131
Re: How to detect keypress from another profile?
« Reply #4 on: May 07, 2023, 06:29:18 PM »
Ahh .  That's right ..  sorry.  I should have remembered that.  So even if some other profile's command presses a key, I should be able to capture it ok my polling command. ?  Will put it in later and confirm.  Thanks

What I'd really like is some type of screen reader integrated  within VA to verify a section of the game's screen state to determine if an action was truly performed   but I guess that'll be borderline and trigger a potential strike with EC soft etc ...

Starblue7

  • Full Member
  • ***
  • Posts: 131
Re: How to detect keypress from another profile?
« Reply #5 on: May 08, 2023, 05:30:46 AM »
I misinterpreted what you were initially saying as wanting to trigger a command based on a keypress from another command.

If you're using either the "Device State" tab, or the "{STATE_KEYSTATE:}" token, that should return the state of a given key including when it's pressed by VoiceAttack itself.


If you're using a loop, especially one containing a lot of actions, it may just be missing the press (I.E. it's checking before or after the command begins pressing or has already released the key, respectively)

So yeah..  Issue is, in my Profile #2, I have a command already set up to do various things using the same 'F7' Key.

So, when Profile #1's command is executed and hits the 'F7' key, of course my polling command running in the background in Profile #2 will recognize this, but it will also recognize a command triggered in my Profile #2 when I press the 'F7' key as well.
Even though 'Do Not Allow Key To Be Passed Through' for that command.

So it's kinda like I need a way to determine if I MYSELF pressed the 'F7' Key from Profile #2, or the 'F7' key press came from Profile #1.

I think I need some more good ideas for this.

Starblue7

  • Full Member
  • ***
  • Posts: 131
Re: How to detect keypress from another profile?
« Reply #6 on: May 08, 2023, 10:01:04 PM »
@Pfeil

Besides the EASY (IMO) way of doing things above, re, having some token or something detect if the keypress came from another profile or not.

I have tried using a polling loop to monitor what's going on:

#1.  In Profile #2:  If user triggers a command by pressing the 'F7' key, then that command will set a global Boolean variable:  Var_notMYPROFILE = True
The Polling command in Profile #2 should recognize that the 'F7' key was pressed physically (due to the Var_notMYPROFILE variable being TRUE) based on the command in Profile #2, and do something specific.

#2.  In Profile #1:  If the 'F7' key is pressed down from a command kicked off from Profile #1 and the global Boolean variable:  Var_notMYPROFILE = FALSE ,  then the polling command in Profile #2 does something different.

HOWEVER,

In doing testing, it seems that my polling command (which detects the 'F7' keypress) will NOT recognize the global Boolean variable's value when changed.  Even if I put in a loop and wait until it the Boolean is set, the command still won't acknowledge it...  If the Polling command recognized the variable to be TRUE, then it should ignore.
The TIMER in the below code is there just to see if that's causing any issue, but still doesn't make a difference.

Here is my below code so far.

Profile #2 - 'F7' Command   (Do not allow key to be passed through / Shortcut is invoked when all keys are released)
Code: [Select]
Set Boolean [Var_notMYPROFILE] to True
    Begin Boolean Compare : [Var_ChatWindow] Equals False
        Press F7 key and hold for 0.1 seconds and release
        Say, 'Hello World from My Profile'
    End Condition
Set Boolean [Var_notMYPROFILE] to False

Profile #2 - POLLING Command (running...)
Code: [Select]
Start Indefinite Loop   
   Begin Condition : ([{STATE_KEYSTATE:F7}] Equals '1' AND [Var_notMYPROFILE] Equals False)
      Set date [~F7_Timer] to [~F7_Timer] plus [5] seconds
      Start Loop While : [~F7_Timer] Is After Or Equals Current Date/Time
         Begin Boolean Compare : [Var_notMYPROFILE] Equals True
            Loop Break
         End Condition
      End Loop
      Begin Boolean Compare : [Var_notMYPROFILE] Equals False
         Say, 'Hello World from OTHER Profile'
      End Condition
   End Condition
End Loop

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: How to detect keypress from another profile?
« Reply #7 on: May 08, 2023, 10:39:15 PM »
Use the "Write a Value to the Event Log" action to output the values of the variables and tokens you're checking.

Understanding how to debug your commands is essential when using advanced features.

Starblue7

  • Full Member
  • ***
  • Posts: 131
Re: How to detect keypress from another profile?
« Reply #8 on: May 09, 2023, 12:10:12 AM »
Use the "Write a Value to the Event Log" action to output the values of the variables and tokens you're checking.

Understanding how to debug your commands is essential when using advanced features.

Actually, what's not included in the code above is my Text to Speech lines.

I uses these lines to tell me what variable values are what as I run a command and step through things.

In that case, the Boolean Var_notMYPROFILE value of TRUE was not being recognized by the pooling command.
Even though I pressed the 'F7' key.
To which I can only chop that up to some timing issue.
Which is why I have the timer loop in the polling command in order to try to capture the Boolean.

It still doesn't.  So I'm left thinking that when I press the 'F7' key, the POLLING command picks up the KEYSTATE of that press even before the 'F7' command itself, and then somehow just locks out the 'F7' command from updating the global variable and or reading any global variable set by the 'F7' command itself.

I mean,  if the 'F7' Command actually set the global boolean variable to TRUE, then by all rights the LOOP in my Polling command should at least recognize that, but again, on my variable check in that section, it doesn't.

I suppose I'll try to fiddle with it more....

Welcome anyone else as well within the community to offer their thoughts.

Thanks!

Starblue7

  • Full Member
  • ***
  • Posts: 131
Re: How to detect keypress from another profile?
« Reply #9 on: May 09, 2023, 05:44:29 AM »

Profile #2 - 'F7' Command   (Do not allow key to be passed through / Shortcut is invoked when all keys are released)
Code: [Select]
Set Boolean [Var_notMYPROFILE] to True
    Begin Boolean Compare : [Var_ChatWindow] Equals False
        Press F7 key and hold for 0.1 seconds and release
        Say, 'Hello World from My Profile'
    End Condition
Set Boolean [Var_notMYPROFILE] to False

Profile #2 - POLLING Command (running...)
Code: [Select]
Start Indefinite Loop   
   Begin Condition : ([{STATE_KEYSTATE:F7}] Equals '1' AND [Var_notMYPROFILE] Equals False)
      Set date [~F7_Timer] to [~F7_Timer] plus [5] seconds
      Start Loop While : [~F7_Timer] Is After Or Equals Current Date/Time
         Begin Boolean Compare : [Var_notMYPROFILE] Equals True
            Loop Break
         End Condition
      End Loop
      Begin Boolean Compare : [Var_notMYPROFILE] Equals False
         Say, 'Hello World from OTHER Profile'
      End Condition
   End Condition
End Loop

So....  Above wasn't working out that well and I figured it was because I wasn't resetting the ~F7_Timer after it's use in the indefinite loop.

Modified code below:
It seems to be working much better (or as intended now), and can't say the below is ideal or in some final form.  But from now putting it thru some rigorous testing.

Code: [Select]
Start Indefinite Loop
   Begin Condition : ([{STATE_KEYSTATE:F7}] Equals '1' AND [Var_notMYPROFILE] Equals False)
      Set date [~F7_Timer] to [~F7_Timer] plus [2500] milliseconds
      Start Loop While : [~F7_Timer] Is After Or Equals Current Date/Time
         Begin Boolean Compare : [Var_notMYPROFILE] Equals True
            Set decimal [~F7_Timer] value to the converted value of {DATETICKS}
            Loop Break
         End Condition
      End Loop
      Write [Blue] '[PROFILE #2] TIME IN MILLISECONDS:  {TIMEMILLISECOND}' to log
      Begin Boolean Compare : [Var_notMYPROFILE] Equals False
         Say, 'Hello World from OTHER Profile'
      End Condition
      Set date [~F7_Timer] value to [Not Set]    <--------------------------------- ADDED
    End Condition
End Loop