File size: 699 Bytes
136c905
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# main.py
import keyboard
from candidate_window import CandidateWindow
from engine import Engine

cw = CandidateWindow()
engine = Engine()

def on_key(e):
    if e.event_type != "down":
        return

    # ESC 隐藏
    if e.name == "esc":
        cw.hide()
        engine.reset()
        return

    # 普通字符
    if len(e.name) == 1:
        candidates = engine.input(e.name)

        text = "\n".join([
            f"{i+1}. {c}" for i, c in enumerate(candidates)
        ])

        cw.set_text(text)
        cw.show()

    # 空格选择(模拟)
    if e.name == "space":
        engine.reset()
        cw.hide()

keyboard.hook(on_key)

cw.start()