new interface may be unreadable, raise an appropriate IOError
[pyhdaps.git] / hdaps-pivot
blob28ceab55bba2b2eb591a81d02afddefd0093864d
1 #!/usr/bin/env python
3 '''
4 hdaps-pivot - read hdaps position and print it
5 '''
7 # Copyright: 2008-2009 Evgeni Golov <sargentd@die-welt.net>
8 # License: GPL-2
10 from hdaps import *
11 from time import sleep
12 import getopt
13 import sys
15 __version__ = "0.1"
17 def pivot(count=1000, verbose=False):
18 calX,calY = readPosition(True)
19 print '(x,y) base: (%u,%u)' % (calX, calY)
20 for i in range(0,count):
21 posX,posY = readPosition()
22 print '(x,y) position: (%i,%i)' % (posX-calX, posY-calY)
23 if verbose:
24 print 'keyboard=%i mouse=%i' % (readKeyboardActivity(), readMouseActivity())
25 sleep(0.25)
27 def usage():
28 print 'hdaps-pivot from pyhdaps, version %s' % __version__
29 print '\nOptions:'
30 print '\t-c, --count <count>\tthe count of rounds it will print'
31 print '\t-v, --verbose\tprint also keyboard and mouse activity'
33 def main():
34 try:
35 opts, args = getopt.getopt(sys.argv[1:], "hc:v", ["help", "count=", "verbose"])
36 except getopt.GetoptError, err:
37 print str(err)
38 usage()
39 sys.exit(2)
40 verbose = False
41 count = 1000
42 for o, a in opts:
43 if o in ("-v", "--verbose"):
44 verbose = True
45 elif o in ("-h", "--help"):
46 usage()
47 sys.exit()
48 elif o in ("-c", "--count"):
49 count = int(a)
51 pivot(count, verbose)
53 if __name__ == '__main__':
54 main()