Saturday, June 17, 2017

click on screen position by following number

***** mouse-screen.py *********
import sys
from PyQt4 import QtGui, QtCore
import os
from PyQt4.QtGui import *
from datetime import datetime



pox1 = 341
poy1 = 273

pox2 = 778
poy2 = 1011

class Example(QtGui.QWidget):
   
    def __init__(self):
        super(Example, self).__init__()
       
        self.initUI()
    def keyPressEvent(self, event):
        if event.key() == QtCore.Qt.Key_Escape: # QtCore.Qt.Key_Escape is a value that equates to what the operating system passes to python from the keyboard when the escape key is pressed.
            self.close()
        elif event.key() == QtCore.Qt.Key_2:
            os.system("nohup python xdotool.py " + str(pox1) + " " + str(poy1) + "&")
            self.close()
        elif event.key() == QtCore.Qt.Key_3:
            os.system("nohup python xdotool.py " + str(pox2) + " " + str(poy2) + "&")
            self.close()

       
    def initUI(self):
        newfont = QtGui.QFont("Times", 14, QtGui.QFont.Bold)

        # lbl1 = QtGui.QLabel('ZetCode', self)
        # lbl1.move(15, 10)

        lbl2 = QtGui.QLabel('2', self)
        lbl2.setObjectName('lbl2')
        lbl2.setStyleSheet("QLabel#lbl2 {color: red}")
        lbl2.setFont(newfont)
        lbl2.move(pox1, poy1)
       
        lbl3 = QtGui.QLabel('3', self)
        lbl3.setObjectName('lbl3')
        lbl3.setStyleSheet("QLabel#lbl3 {color: red}")
        lbl3.setFont(newfont)
        lbl3.move(pox2, poy2)    
       
        # self.setGeometry(300, 300, 250, 150)
        p = QPixmap.grabWindow(QApplication.desktop().winId())
        # lbl = QLabel()
        # lbl.setPixmap(p)
        palette = QPalette()
        palette.setBrush(10, QBrush(p))                     # 10 = Windowrole
        self.setPalette(palette)

        self.setWindowTitle('mouse-screen.py')   
        self.show()
       
def main():
   
    app = QtGui.QApplication(sys.argv)

    ex = Example()

    sys.exit(app.exec_())


if __name__ == '__main__':
    main()





****xdotool.py *********
#!/usr/bin/python

import os
import sys
import time

pox = sys.argv[1]
poy = sys.argv[2]

time.sleep(0.15)
os.system("xdotool mousemove " + pox + " " + poy)
os.system("xdotool click 1")





**** usage ***
$ python mouse-screen.py

it will screen number 2 on screen position 341, 273, when we press 2 it will click on the position

and

it will screen number 3 on screen position 778 , 1011, when we press 2 it will click on the position

No comments:

Post a Comment