diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2024-11-17 17:11:39 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2024-11-17 17:19:00 +1300 |
commit | 1364fafee00ec00370c80f85a27c65863d536ad2 (patch) | |
tree | 15a3a3b508bea3ea534514bcac519714b0fa35a1 | |
parent | Simplify/clarify editor selection logic (diff) | |
download | vixf-1364fafee00ec00370c80f85a27c65863d536ad2.tar.gz vixf-1364fafee00ec00370c80f85a27c65863d536ad2.zip |
Refactor keyboard automation
-rw-r--r-- | vixf.py3 | 23 |
1 files changed, 11 insertions, 12 deletions
@@ -13,7 +13,7 @@ import subprocess import tempfile import time -import pynput +from pynput.keyboard import Key, Controller import pyperclip SELF = 'vixf' @@ -22,19 +22,18 @@ SLEEP = 0.5 EDITOR = 'vi' -keyboard = pynput.keyboard.Controller() +keyboard = Controller() time.sleep(SLEEP) -ctrl = pynput.keyboard.Key.ctrl +# Select all +with keyboard.pressed(Key.ctrl): + keyboard.type('a') -keyboard.press(ctrl) -keyboard.type('a') -keyboard.release(ctrl) +# Copy +with keyboard.pressed(Key.ctrl): + keyboard.type('c') -keyboard.press(ctrl) -keyboard.type('c') -keyboard.release(ctrl) with tempfile.NamedTemporaryFile(mode='w', delete_on_close=False) as tf: tf.write(pyperclip.paste()) @@ -66,6 +65,6 @@ pyperclip.copy(content) time.sleep(SLEEP) -keyboard.press(pynput.keyboard.Key.ctrl) -keyboard.type('v') -keyboard.release(pynput.keyboard.Key.ctrl) +# Paste +with keyboard.pressed(Key.ctrl): + keyboard.type('v') |