示例#1
1
    def tick(self):
        now = time.asctime(time.localtime())
        changed, modifiers, keys = kl.fetch_keys()
        if(self.previous_key == "<caps lock>") :
            if(keys == "<esc>") :
                return False            
            elif(not keys and modifiers["left shift"] ) :
                self.caps = False
                self.selected+=1
                if(self.selected > (self.lines - 1) or self.selected > len(self.result)) :
                    self.selected = 0
                self.previous_key = ""
        if keys : 
            if(len(keys) == 1 and keys not in self.end_chars) :
                self.word += str(keys)
            elif(keys == "<backspace>"):
                self.word = self.word[0:-1]
            elif(self.result and keys == "<caps lock>" and self.previous_key == "<caps lock>") :
                v = virtkey.virtkey()
                for i in range(len(self.word), len(self.result[self.selected])) :
                    v.press_unicode(ord(self.result[self.selected][i]))
                    v.release_unicode(ord(self.result[self.selected][i]))
                v.press_unicode(ord(" "))
                v.release_unicode(ord(" "))
                self.selected = 0
                self.word = ""
                self.result = []
            elif(keys == "<caps lock>") :
                self.caps = True
                self.previous_key = keys
            else:
                self.word = ""

            if(keys != "<caps lock>") :
                self.caps = False

            self.previous_key = keys

            if(self.word):
                #raw_result = subprocess.Popen(['look', self.word], stdout=subprocess.PIPE).communicate()[0]
                #self.result = string.split(raw_result)
                self.result = self.wb.getWords(self.word)
            else:
                self.result = []

        if(self.caps) :
            self.osd.set_colour("green")
        else :
            self.osd.set_colour("white")

        for i in range(10):
            if(len(self.result) > i):
                if(i == self.selected):
                    self.osd.display("[ " + self.result[i] + " ]", line = i)
                else :
                    self.osd.display("  " + self.result[i], line = i)
            else :
                self.osd.display("", line = i)
                
        return True
示例#2
0
 def fetch_word(self):
     changed, modifiers, keys = fetch_keys()
     if changed:
         if modifiers['left ctrl'] and modifiers['left shift']:
             word = os.popen('xsel').read().strip()
             if word:
                 self.put_or_print_or_quit(word)
示例#3
0
 def fetch_word(self):
     changed, modifiers, keys = fetch_keys()
     if changed:
         if modifiers['left ctrl'] and modifiers['left shift']:
             word = os.popen('xsel').read().strip()
             if word:
                 self.put_or_print_or_quit(word)
示例#4
0
文件: main.py 项目: gridl/Wallnote
    def __init__(self):
        self.data = OrderedDict()
        self.flag_end = True     # default bool for logging hault state
        self.flag_start = False  # default bool for logging start state
        self.flag_master = False
        self.escape = False
        self.ignore_keys = ["<left ctrl>", "<left shift>", "<right shift>",
                            "<backspace>", "<esc>", "<enter>", "<caps lock>", "<right ctrl>"]
        setproctitle('Wallnote')

        # load saved data
        load_data = self.load_pickle()
        if load_data:
            self.data = load_data
        # know where to add new data
        if load_data and len(load_data):
            self.ins_pos = len(self.data)
        else:
            self.ins_pos = 0
        # start recording
        #keylogger.log(self.read_keys)
        while True:
            sleep(0.0001)
            changed, modifiers, keys = keylogger.fetch_keys()
            if changed:
                self.read_keys(keys)
 def run(self):
     while self.running:
         sleep(self.sleep_interval)
         changed, modifiers, keys = fetch_keys()
         if changed:
             self.respond(modifiers)
示例#6
0
def log(callback, sleep_interval=.05):
    while 1:
        sleep(sleep_interval)
        changed, modifiers, keys = fetch_keys()
        if changed:
            callback(modifiers, search)
 def run(self):
     while self.running:
         sleep(self.sleep_interval)
         changed, modifiers, keys = fetch_keys()
         if changed:
             self.respond(modifiers)