commit 185ea5dac2616dd01ff27009a8865afd1698bfd7
Author: U-osh-PC\osh <osh@oshgnacknak.de>
Date: Sun, 4 Nov 2018 12:22:21 +0100
Initaial commit.
Diffstat:
3 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
@@ -0,0 +1,3 @@
+# Autotype in python
+
+Automatically sends keystokes after a delay
diff --git a/retype.py b/retype.py
@@ -0,0 +1,41 @@
+from pynput.keyboard import Controller, Key
+import time
+from optparse import OptionParser
+import sys
+
+keyboard = Controller()
+
+def typeChar(c):
+ keyboard.press(c)
+ time.sleep(0.001)
+ keyboard.release(c)
+ time.sleep(0.005)
+
+
+def typeLine(line):
+ for c in line:
+ typeChar(c)
+ typeChar(Key.enter)
+
+def parseArgs():
+ parser = OptionParser(description="Retypes the given text like a keyboard.")
+ parser.add_option("-m", "--message", dest="message",
+ help="the MSG to send. reading from STDIN if none is provided", metavar="MSG")
+ parser.add_option("-d", "--delay",
+ dest="delay", default=700, type="int",
+ help="the DELAY before typing the text in ms. Deafault is 700", metavar="DELAY")
+ return parser.parse_args()
+
+def main():
+ options, args = parseArgs()
+ time.sleep(options.delay / 1000)
+ if options.message:
+ lines = options.message.split("\n")
+ else:
+ lines = [l.strip() for l in sys.stdin]
+ for line in lines:
+ typeLine(line)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/testfile b/testfile
@@ -0,0 +1,3 @@
+Halle Welt, wie geht es?
+
+Mir geht es gut