Skip to content

Commit

Permalink
Adding filetranscriber to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
SavinaRoja committed May 24, 2014
1 parent 3e9a635 commit 28eee06
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions examples/filetranscriber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
FileTranscriber
A small utility that simulates user typing to aid plaintext file transcription
in limited environments
Usage:
transcribe <file> [--interval=<time>] [--pause=<time>]
transcribe (--help | --version)
Options:
-v --version show program's version number and exit
-h --help show this help message and exit
-i --interval=<time> Interval between keystrokes (in seconds). Typing too
quickly may break applications processing the
keystrokes. [default: 0.1]
-p --pause=<time> How long the script should wait before starting (in
seconds). Increase this if you need more time to enter
the typing field. [default: 5]
"""

#This script copied from https://github.com/SavinaRoja/FileTranscriber
#Check there for updates

from docopt import docopt
from pykeyboard import PyKeyboard
from pymouse import PyMouseEvent
import time
import sys


#Hack to make input work for both Python 2 and Python 3
try:
input = raw_input
except NameError:
pass


class AbortMouse(PyMouseEvent):
def click(self, x, y, button, press):
if press:
self.stop()


def main():
#Get an instance of PyKeyboard, and our custom PyMouseEvent
keyboard = PyKeyboard()
mouse = AbortMouse()

input('Press Enter when ready.')
print('Typing will begin in {0} seconds...'.format(opts['--pause']))
time.sleep(opts['--pause'])

mouse.start()
with open(opts['<file>'], 'r') as readfile:
for line in readfile:
if not mouse.state:
print('Typing aborted!')
break
keyboard.type_string(line, opts['--interval'])

if __name__ == '__main__':
opts = docopt(__doc__, version='0.2.1')
try:
opts['--interval'] = float(opts['--interval'])
except ValueError:
print('The value of --interval must be a number')
sys.exit(1)
try:
opts['--pause'] = float(opts['--pause'])
except ValueError:
print('The value of --pause must be a number')
sys.exit(1)
main()

0 comments on commit 28eee06

Please sign in to comment.