import sys, os, xvis, time, math
from PyQt4.QtCore import *
from PyQt4.QtGui import *
def __init__(self, parent):
self.setMouseTracking(True)
self.last_update = 0
self.reset_interval = 100
self.middle_x = app.desktop().screenGeometry().width() / 2.0
self.middle_y = app.desktop().screenGeometry().height() / 2.0
def get_cursor_change(self):
"""Return (x,y) tuple of cursor change"""
self.last_update += 1
diff = cursor - self.last_cursor
self.last_cursor = cursor
if self.last_update > self.reset_interval:
# move cursor to middle of screen
QCursor.
setPos(self.
middle_x, self.
middle_y) self.
last_cursor = QPoint(self.
middle_x, self.
middle_y) self.last_update = 0
return (diff.x(), diff.y())
def mouseMoveEvent(self, event):
event.accept()
def __init__(self, parent=None):
self.driver = Driver(self)
self.setCentralWidget(self.driver)
# run loop
self.connect(timer, SIGNAL("timeout()"), self.update)
timer.start(50)
def update(self):
"""Gets called each iteration"""
cursor_change = self.driver.get_cursor_change()
print cursor_change
if __name__ == "__main__":
mainwindow = MainWindow()
mainwindow.show()
mainwindow.raise_()
sys.exit(app.exec_())
import sys, os, xvis, time, math
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Driver(QWidget):
def __init__(self, parent):
QWidget.__init__(self, parent)
self.setMouseTracking(True)
self.last_cursor = QCursor.pos()
self.last_update = 0
self.reset_interval = 100
self.middle_x = app.desktop().screenGeometry().width() / 2.0
self.middle_y = app.desktop().screenGeometry().height() / 2.0
def get_cursor_change(self):
"""Return (x,y) tuple of cursor change"""
self.last_update += 1
cursor = QCursor.pos()
diff = cursor - self.last_cursor
self.last_cursor = cursor
if self.last_update > self.reset_interval:
# move cursor to middle of screen
QCursor.setPos(self.middle_x, self.middle_y)
self.last_cursor = QPoint(self.middle_x, self.middle_y)
self.last_update = 0
return (diff.x(), diff.y())
def mouseMoveEvent(self, event):
event.accept()
class MainWindow(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
self.driver = Driver(self)
self.setCentralWidget(self.driver)
# run loop
timer = QTimer(self)
self.connect(timer, SIGNAL("timeout()"), self.update)
timer.start(50)
def update(self):
"""Gets called each iteration"""
cursor_change = self.driver.get_cursor_change()
print cursor_change
if __name__ == "__main__":
app = QApplication(sys.argv)
mainwindow = MainWindow()
mainwindow.show()
mainwindow.raise_()
sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode
...
(0, 45)
(-56, 63)
(-49, 18)
(-59, -39)
(-11, -98)
(51, -30)
(98, 30)
(44, 68)
(-59, 60)
(-96, 19)
(0, 0)
(0, 0)
(0, 0)
(0, 0)
(0, 0)
(4, 91)
(-23, 44)
(-54, 3)
(-98, -44)
(-52, -86)
(43, -76)
(63, -3)
(56, 47)
(5, 84)
(-68, 72)
(-83, 18)
(-109, -34)
(-61, -52)
(18, -44)
...
...
(0, 45)
(-56, 63)
(-49, 18)
(-59, -39)
(-11, -98)
(51, -30)
(98, 30)
(44, 68)
(-59, 60)
(-96, 19)
(0, 0)
(0, 0)
(0, 0)
(0, 0)
(0, 0)
(4, 91)
(-23, 44)
(-54, 3)
(-98, -44)
(-52, -86)
(43, -76)
(63, -3)
(56, 47)
(5, 84)
(-68, 72)
(-83, 18)
(-109, -34)
(-61, -52)
(18, -44)
...
To copy to clipboard, switch view to plain text mode
Bookmarks