2shea / talon_configs

Modules to be used with Talon for hands-free input
MIT License
100 stars 10 forks source link

run this command and enter #4

Open 2shea opened 5 years ago

2shea commented 5 years ago

e.g., don't have to say "enter" after all git commands like "run get commit enter"

2shea commented 5 years ago

https://github.com/talonvoice/talon/issues/58

from talon import ctrl
from talon.engine import engine
from talon.voice import Context

enter_flag = False

def on_phrase_post(j):
    global enter_flag
    if j['cmd'] == 'p.end':
        phrase = j['phrase']
        if enter_flag and phrase and phrase[-1] == 'run':
            print('HELLO')
            enter_flag = False
            ctrl.key_press('enter')

def set_enter_flag(m):
    global enter_flag
    enter_flag = True

engine.register('post:phrase', on_phrase_post)

ctx = Context('hmm')
ctx.keymap({'run': set_enter_flag})

or lambda m: cron.after('0.5s', lambda: ctrl.key_press('enter'))