-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkey_patterns.py
61 lines (51 loc) · 1.65 KB
/
key_patterns.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
from os.path import exists, join
import os, threading
from jca.qter.qter_test import *
from jca.qter.core.link_browser import LinkBrowser
from jca.files.all_files.all_files import all_files
from jca.files import my_paths
import pyHook
import pythoncom
class v:
keys_pressed = []
searching = False
def save(word1, word2):
Write word1, word2
We want to know likelihood of word2 coming after word1
def info_handler(attrs):
def event_info(e):
if e.MessageName == 'key down':
v.keys_pressed.append(e.Key)
limit = 100
if len(v.keys_pressed) > limit:
v.keys_pressed = v.keys_pressed[-limit:]
curr_word = ''
for ch in v.keys_pressed[::-1]:
if ch == 'Space':
if word_before:
store_word(word_before, curr_word)
word_before = curr_word
curr_word = ch + word
return True
return event_info
def search(text):
v.searching = True
link_browser.setPlainText('')
for path in all_files(my_paths.jca, pattern='*.py', ignore_dirs=True,
recursive=True):
with open(path) as file:
if text.lower() in unicode(file.read().lower(),
'ascii', 'replace'):
link_browser.add_line('"%s"' % path)
link_browser.repaint()
v.searching = False
start_if_havent()
hm = pyHook.HookManager()
hm.KeyDown = info_handler(['Ascii', 'Key', 'KeyID', 'ScanCode', 'Extended',
'Injected', 'Alt', 'Transition'])
hm.HookKeyboard()
t = threading.Thread(target=pythoncom.PumpMessages, args=[], kwargs={})
t.start()
link_browser = LinkBrowser()
link_browser.show()
launch_if_havent()