Add hdaps-pivot, emulating the behaviour of the old pivot.c
[pyhdaps.git] / hdaps-pivot
blob2b1a5db4550c6453df88b62cfa5ec66a61609232
1 #!/usr/bin/env python
3 '''
4 hdaps-pivot - read hdaps position and print it
5 '''
7 from hdaps import *
8 from time import sleep
9 import getopt
10 import sys
12 __version__ = "0.1"
14 def pivot(count=1000, verbose=False):
15 calX,calY = readPosition(True)
16 print '(x,y) base: (%u,%u)' % (calX, calY)
17 for i in range(0,count):
18 posX,posY = readPosition()
19 print '(x,y) position: (%i,%i)' % (posX-calX, posY-calY)
20 if verbose:
21 print 'keyboard=%i mouse=%i' % (readKeyboardActivity(), readMouseActivity())
22 sleep(0.25)
24 def usage():
25 print 'hdaps-pivot from pyhdaps, version %s' % __version__
26 print '\nOptions:'
27 print '\t-c, --count <count>\tthe count of rounds it will print'
28 print '\t-v, --verbose\tprint also keyboard and mouse activity'
30 def main():
31 try:
32 opts, args = getopt.getopt(sys.argv[1:], "hc:v", ["help", "count=", "verbose"])
33 except getopt.GetoptError, err:
34 print str(err)
35 usage()
36 sys.exit(2)
37 verbose = False
38 count = 1000
39 for o, a in opts:
40 if o in ("-v", "--verbose"):
41 verbose = True
42 elif o in ("-h", "--help"):
43 usage()
44 sys.exit()
45 elif o in ("-c", "--count"):
46 count = int(a)
48 pivot(count, verbose)
50 if __name__ == '__main__':
51 main()