Author Topic: New Option: Control/Toggle settings based on mouse location  (Read 3876 times)

TheDocBennett

  • Newbie
  • *
  • Posts: 14
New Option: Control/Toggle settings based on mouse location
« on: August 20, 2020, 06:29:58 AM »
This would help users who have KVM or multi-system setups where they would want Voiceattack to do/not do something based on mouse X/Y.

For my use-case, I use the Multiplicity software to unite my keyboard and mouse to control both my PC and the laptop I have parked under the monitor. I have a command in VA now on both machines using a C# script to detect which machine is in use and then it toggles listening on/off when the mouse is "parked" in the top or bottom pixel-row of the screen. This checks and rechecks the mouse location often.

Constantly having this command running has caused some issues and often needs to be "reset" to keep working smoothly.

I believe other users could make use of an option like this for other scenarios, too.

I have attached a gif that shows this command.




Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4761
  • RTFM
Re: New Option: Control/Toggle settings based on mouse location
« Reply #1 on: August 20, 2020, 08:35:19 AM »
Constantly having this command running has caused some issues and often needs to be "reset" to keep working smoothly.

Can you elaborate on these issues?


As a side note, you can right-click the action list and choose "Copy All as Text" from the context menu, so you can then paste the contents of your command into code tags (click the "#" button to add them) in your post.

TheDocBennett

  • Newbie
  • *
  • Posts: 14
Re: New Option: Control/Toggle settings based on mouse location
« Reply #2 on: August 20, 2020, 09:56:57 AM »
I suppose it is mostly about QOL/annoyance. My personal use of VA extends far more into my job (home office) than gaming. During any hour I probably switch my focus between my PC and Laptop more than one hundred times. The same profile of over 1k commands is running on both machines, and specifically the "only listen form this machine" gets to be aggrevating. I'm using Voicemeeter to pipe my PC's mic to the Laptop, so they can both "hear" me at the same time.

I guess the real ask is if there is a better way than the below commands, or if this could possibly be achieved with some small setting addition to toggle listening or other options. Again, it's mostly just an annoyance when the two get "out of sync" and both activate something or take an action I only want to happen on one machine.


Good to know about the copy option, here is the command actions. I had a lot of help from Pfeil doing this, I still owe him a beer/coffee/tea...
Code: [Select]
Begin Text Compare : [{STATE_LISTENING}] Equals '1'
    Set Boolean [~lastListeningState] to True
Else
    Set Boolean [~lastListeningState] to False
End Condition
Inline C# Function: Get Machine Name
Write [Purple] 'Mouse Listening Running/Reset' to log
Play sound, '{VA_SOUNDS}\LCARS\Trek Core__computerbeep_40.wav'
Start Loop While : [1] Equals [1]
    Begin Condition : ([~MachineName] Equals 'CENTRALDOGMA' AND Mouse Y (Screen) Is Greater Than 1438) OR ([~MachineName] Equals 'Casper' AND Mouse Y (Screen) Is Less Than 10)
        Begin Date Compare : [~timeAtOffPosition] Has Been Set
            Begin Date Compare : [~timeAtOffPosition] Is Before Current Date/Time
                Begin Boolean Compare : [~lastListeningState] Equals True
                    Stop VoiceAttack listening
                    Write [Yellow] 'LISTENING PAUSED: MOUSE OFF SCREEN' to log
                    Write (overwrite), 'CASPER' to file 'D:\VAListening\vastate.txt'
                    Set Boolean [~lastListeningState] to False
                End Condition
            End Condition
        Else
            Set date [~timeAtOffPosition] to [~timeAtOffPosition] plus [500] milliseconds
            Set date [~timeAtOnPosition] value to [Not Set]
        End Condition
    Else
        Begin Date Compare : [~timeAtOnPosition] Has Been Set
            Begin Date Compare : [~timeAtOnPosition] Is Before Current Date/Time
                Begin Boolean Compare : [~lastListeningState] Equals False
                    Start VoiceAttack listening
                    Write (overwrite), 'CENTRAL DOGMA' to file 'D:\VAListening\vastate.txt'
                    Write [Green] 'LISTENING RESUMED: MOUSE ON SCREEN' to log
                    Set Boolean [~lastListeningState] to True
                End Condition
            End Condition
        Else
            Set date [~timeAtOnPosition] to [~timeAtOnPosition] plus [500] milliseconds
            Set date [~timeAtOffPosition] value to [Not Set]
        End Condition
    End Condition
End Loop

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4761
  • RTFM
Re: New Option: Control/Toggle settings based on mouse location
« Reply #3 on: August 20, 2020, 11:58:51 AM »
I guess the real ask is if there is a better way than the below commands, or if this could possibly be achieved with some small setting addition to toggle listening or other options.
What would you consider a "better way"? A native option would still need to do the exact same thing, I.E. checking the position of the mouse cursor, which would have the same effect.

it's mostly just an annoyance when the two get "out of sync" and both activate something or take an action I only want to happen on one machine.
How do the listening states get "out of sync"? Is the mouse cursor not making it to the edge of the screen, perhaps if you move it at high speed?

TheDocBennett

  • Newbie
  • *
  • Posts: 14
Re: New Option: Control/Toggle settings based on mouse location
« Reply #4 on: August 20, 2020, 12:12:11 PM »
Better way:
Yeah, I'm stumped too. The commands you provided work fine - my point of suggesting was just if someone/more people had a use-case for this.

Out of Sync:
In my testing of this, it seems to often involve any full-screen applications. Playing a game that doesn't show a cursor sometimes still triggers the listen/don't listen to toggle or when closing the game I just have to reset it all.

I'm quite happy continuing with the solution you graciously provided, just wanted to float the idea out there.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4761
  • RTFM
Re: New Option: Control/Toggle settings based on mouse location
« Reply #5 on: August 20, 2020, 12:31:45 PM »
Games often force the mouse cursor to stay in the center of the screen, which would obviously interfere with checking whether it's near the edge (part of that may also be problematic when combined with the KVM software).

KVM software uses a number of "tricks" to allow the apparent switching of control between machines, however Windows is not actually designed with that functionality in mind. Because of this, there is no built-in method for determining whether you're controlling the current machine, or another one.

I had a look at the documentation for the software you're using, but what scarce information there is on it does not mention any functionality that would allow another application to interact with it, E.G. to check whether the current machine has focus or not.

TheDocBennett

  • Newbie
  • *
  • Posts: 14
Re: New Option: Control/Toggle settings based on mouse location
« Reply #6 on: September 12, 2020, 07:51:38 AM »
If you are still out there @Pfeil, I think there is another bit of info I've sorted out for this.

Again, maybe a super unique scenario, but I've realized the script which is monitoring the movement and location of the mouse to toggle listening on/off has an overlap on my side/portrait monitors.

Code: [Select]
    Begin Condition : ([~MachineName] Equals 'DESKTOPPCNAME' AND Mouse Y (Screen) Is Greater Than 1438) OR ([~MachineName] Equals 'LAPTOPNAME' AND Mouse Y (Screen) Is Less Than 10)

My main PC screen is in the middle (3440x1440) but I have two 1080x1920 (portrait) screens on the left/right of that center ultrawide.

So when I use my KVM software and drag my mouse "off" the bottom of the center monitor it is fine. VA sees my mouse no longer moving and with a Y coordinate greater than 1438 (2 pixel parking area).

However, if my mouse is over on my side monitors they can travel down to where their location is > 1438. The bottom 482 pixels on each side monitor will also meet the condition and disable listening. That is the loophole.

I'm not seeing a way for VA to consider which display the mouse is on, only raw coordinates.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4761
  • RTFM
Re: New Option: Control/Toggle settings based on mouse location
« Reply #7 on: September 12, 2020, 08:52:42 AM »
You can deduce from the X coordinate which monitor the cursor is on, and use that to check for a different Y threshold value.

E.G.
Code: [Select]
Begin Condition : ([~MachineName] Equals 'DESKTOPPCNAME' AND Mouse X (Screen) Is Less Than 0 AND Mouse Y (Screen) Is Greater Than 1918) OR ([~MachineName] Equals 'DESKTOPPCNAME' AND Mouse X (Screen) Is Greater Than Or Equals 0 AND Mouse X (Screen) Is Less Than Or Equals 3440 AND Mouse Y (Screen) Is Greater Than 1438) OR ([~MachineName] Equals 'DESKTOPPCNAME' AND Mouse X (Screen) Is Greater Than 3440 AND Mouse Y (Screen) Is Greater Than 1918) OR ([~MachineName] Equals 'LAPTOPNAME' AND Mouse Y (Screen) Is Less Than 10)

Depending on how your displays are arranged the exact coordinates may differ; One way to check the coordinate for the lowest edge of a screen is to open the "Add a Mouse Move Action" dialog, click "Set Position", and observe the coordinates in the bottom left-hand side of the "Capture Mouse Position" dialog

TheDocBennett

  • Newbie
  • *
  • Posts: 14
Re: New Option: Control/Toggle settings based on mouse location
« Reply #8 on: September 12, 2020, 11:12:47 AM »
That worked perfectly - once again and as always you have my many thank!