dictation-toolbox / dragonfly

Speech recognition framework allowing powerful Python-based scripting and extension of Dragon NaturallySpeaking (DNS), Windows Speech Recognition (WSR), Kaldi and CMU Pocket Sphinx
GNU Lesser General Public License v3.0
388 stars 75 forks source link

Double click not working (Kaldi, OSX) #368

Open denvaar opened 2 years ago

denvaar commented 2 years ago

Single click Mouse actions work great, however I cannot get a double click to work. For example, I'd like to hover the cursor over a word and use the double click action to select it. This seems like a bug to me, but maybe I'm doing something wrong.

Mouse("left:2")

I've tried many variations, like adding a pause, or chaining two single click mouse actions together, but nothing seems to do the trick. There is no error in the console either.

I use Kaldi engine and I'm on macOS Monterey Version 12.4 (Macbook pro)

Thanks for the help.

drmfinlay commented 2 years ago

Hello Denver,

Thank you for reporting this problem. It is indeed a bug with the library. It looks like scrolling is broken on macOS too. I'll have both fixed in the next version. That may be some time off, however.

In the meantime, the following code will allow you to double click:

from dragonfly import MappingRule, CompoundRule, Function

# pynput is the input library Dragonfly uses on macOS and should
#  be installed already.
from pynput.mouse import Controller, Button

controller = Controller()

def left_click(n):
    controller.click(Button.left, n)

# Invoke the `left_click' function when "double click" is spoken.
# With a `MappingRule',
class DoubleClickRule1(MappingRule):
    mapping = {
        "double click": Function(lambda: left_click(2)),
    }

# or `CompoundRule'.
class DoubleClickRule2(CompoundRule):
    spec = "double click"
    def _process_recognition(self, node, extras):
        left_click(2)

Triple click is broken too. Invoke the left_click function with 3 instead to triple click.

Hope this helps!

denvaar commented 2 years ago

Thanks @Danesprite 👍

drmfinlay commented 2 years ago

No problem. I should have these bugs fixed soon.

drmfinlay commented 2 years ago

This is fixed on the master branch. There is one limitation though. Double-click and triple-click will only work when the repeat syntax is used:

{
   "double click": Mouse("left:2"),
   "triple click": Mouse("left:3")
}

The following will not work properly on macOS:

Mouse("left, left").execute()
Mouse("left, left, left").execute()

I'll make another comment, and close this issue, after the next release version is out.