-
Notifications
You must be signed in to change notification settings - Fork 0
/
akp.py
66 lines (53 loc) · 1.53 KB
/
akp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import pyperclip
from pynput import keyboard
from pynput.keyboard import Listener
from tkinter import filedialog
import sys
file_path = filedialog.askopenfilename(initialdir="~/Documents/scanlations/texts/", filetypes=(('text files', '.txt'),))
with open(file_path, 'r') as f:
lines = f.readlines()
i = 0
ctrl_pressed = False
def copy_line():
if i < len(lines):
pyperclip.copy(lines[i].strip()) # Remove newline characters
else:
print("Out of lines")
def check_eol():
if i < len(lines):
print(f"Copied line {i}: {lines[i]}")
else:
print("End of file.")
sys.exit()
def on_press(key):
global i, ctrl_pressed
if key == keyboard.Key.ctrl:
ctrl_pressed = True
elif key == keyboard.Key.up and ctrl_pressed:
i += 1
copy_line()
print("+1")
check_eol()
elif key == keyboard.Key.down and ctrl_pressed:
i -= 1
copy_line()
print("-1")
check_eol()
elif key == keyboard.Key.left and ctrl_pressed:
i -= 2
copy_line()
print("-2")
check_eol()
elif key == keyboard.Key.right and ctrl_pressed or key == keyboard.KeyCode.from_char('v') and ctrl_pressed:
i += 2
copy_line()
print("+2")
check_eol()
elif key == keyboard.Key.ctrl:
ctrl_pressed = False
# start copying the first line
copy_line()
# Set up the listener
with Listener(on_press=on_press) as listener:
print("Press 'Ctrl + V' to copy the next line.")
listener.join()