Exemple #1
0
def mouse():
    current = win32api.GetCursorPos()
    cx = lead_x = int(current[0])
    cy = lead_y = int(current[1])
    last = time.time()

    while(True):
            if (ser.inWaiting()>0):
                    xx=ser.readline()
                    xx=int(xx.decode())
                    #print(xx)
                    if win32api.GetAsyncKeyState(ord('X')):
                            sys.exit()
                    elif xx == 77:
                            lead_x=lead_x+3
                    elif xx == 33:
                            lead_x=lead_x-3
                    elif xx == 88:
                            lead_y=lead_y-3
                    elif xx == 22:
                            lead_y=lead_y+3
                    elif xx == 66:
                            p=win32api.GetCursorPos()
                            lclick(p[0],p[1])
                    elif xx == 11:
                            p=win32api.GetCursorPos()
                            rclick(p[0],p[1])
                    elif xx == 1:
                            print("Cursor lost its control")
                            return()
                            #sys.exit()
                    
            win32api.SetCursorPos((lead_x,lead_y))
            time.sleep(0.001)
Exemple #2
0
 def click(self, iX, iY):
     iX = int(iX)
     iY = int(iY)
     if (self.oCommandListener.Flag is False):
         flags, hcursor, (x, y) = win32gui.GetCursorInfo()
         if (self.lastPos != (x, y)):
             print("If you want to block mouse moving press SPACE!")
         self.lastPos = (iX, iY)
         win32api.SetCursorPos((iX, iY))
         win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, iX, iY, 0, 0)
         win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, iX, iY, 0, 0)
         win32api.SetCursorPos((x, y))
         print("Mouse click at", iX, iY)
         return True
     else:
         print("Tried to click at", iX, iX)
         return False
Exemple #3
0
 def __init__(self):
     self.k = PyKeyboard()  # get pykeyboard
     self.software = u'网上股票交易系统5.0'
     self.hWndChildList = 0
     self.para_hld = win32gui.FindWindow(None, self.software)
     if self.IsWindow():
         self.hWndChildList = self.demo_child_windows(self.para_hld)  # get hld
         attr = self.show_window_attr(self.para_hld)
         win32api.SetCursorPos([attr['post'][0], attr['post'][1]])  # Mover to post(x,y)
Exemple #4
0
 def click(self, x, y):
     if (self.device_type == 'emu'):
         win32gui.ShowWindow(self.device_id, win32con.SW_SHOW)
         win32gui.SetForegroundWindow(self.device_id)
         win32api.SetCursorPos([self.device_left + x, self.device_top + y])
         win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
         win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
         time.sleep(0.5)
     elif (self.device_type == 'android'):
         adb.click(x, y)
         time.sleep(0.5)
     return
Exemple #5
0
    def receive_msg(self):
        self.lock.acquire()

        # for this problem: https://bbs.csdn.net/topics/390973288?page=1
        win32api.keybd_event(0x11, 0, 0, 0)  # ctrl
        win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP,
                             0)  # release key

        win32gui.ShowWindow(self.con_hwnd, win32con.SW_MAXIMIZE)
        win32gui.SetForegroundWindow(self.con_hwnd)

        time.sleep(1)

        x_mid = int(win32api.GetSystemMetrics(win32con.SM_CXSCREEN) / 2)
        y_mid = int(win32api.GetSystemMetrics(win32con.SM_CYSCREEN) / 2)
        win32api.SetCursorPos([x_mid, y_mid])

        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0,
                             0)  # left mouse button
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0,
                             0)  # release key

        win32api.keybd_event(0x11, 0, 0, 0)  # ctrl
        win32api.keybd_event(0x41, 0, 0, 0)  # 'a'
        win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP,
                             0)  # release key
        win32api.keybd_event(0x41, 0, win32con.KEYEVENTF_KEYUP,
                             0)  # release key

        win32api.keybd_event(0x11, 0, 0, 0)  # ctrl
        win32api.keybd_event(0x43, 0, 0, 0)  # 'c'
        win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP,
                             0)  # release key
        win32api.keybd_event(0x43, 0, win32con.KEYEVENTF_KEYUP,
                             0)  # release key

        time.sleep(1)

        win32clipboard.OpenClipboard()
        text = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT)
        win32clipboard.CloseClipboard()

        win32gui.SetForegroundWindow(self.cur_hwnd)

        time.sleep(1)

        self.lock.release()

        return text
Exemple #6
0
 def getAllStock(self):
     win32api.keybd_event(VK_CODE['F4'], 0, 0, 0)
     attr = self.show_window_attr(self.para_hld)
     x = attr['post'][0] + 300
     y = attr['post'][1] + 300
     win32api.SetCursorPos([x, y])  # Mover to post(x,y)
     self.copyKey()
     copy_txt = self.getCopyText()
     copy_txt = copy_txt.rstrip().split("\n")
     c = []
     cArray = {}
     cloun = ''
     for vv in copy_txt:
         cloun = vv.split("	")
         for v in cloun:
             c.append(v)
         cArray[c[1]] = c
         c = []
     return cArray
Exemple #7
0
def setCoords(coord):
    win32api.SetCursorPos((x_pad + coord[0], y_pad + coord[1]))
Exemple #8
0
def mouse_pos(pos):
    win32api.SetCursorPos(pos)
Exemple #9
0
def click1(x, y):  #第一种
    win32api.SetCursorPos((x, y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
Exemple #10
0
# 利用api生成Buffer
strBuf = win32gui.PyMakeBuffer(bufSize)
print(strBuf)
# 发送消息获取文本内容
# 参数:窗口句柄; 消息类型;文本大小; 存储位置
length = win32gui.SendMessage(subHandle, win32con.WM_GETTEXT, bufSize, strBuf)
# 反向内容,转为字符串
# text = str(strBuf[:-1])

address, length = win32gui.PyGetBufferAddressAndLen(strBuf)
text = win32gui.PyGetString(address, length)
# print('text: ', text)

# 鼠标单击事件
#鼠标定位到(30,50)
win32api.SetCursorPos([30, 150])
#执行左单键击,若需要双击则延时几毫秒再点击一次即可
win32api.mouse_event(
    win32con.MOUSEEVENTF_LEFTUP | win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
#右键单击
win32api.mouse_event(
    win32con.MOUSEEVENTF_RIGHTUP | win32con.MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)


def click1(x, y):  #第一种
    win32api.SetCursorPos((x, y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)


def click2(x, y):  #第二种
Exemple #11
0
def click(x, y):
    win32api.SetCursorPos((x, y))
Exemple #12
0
def clickk(x, y):
    win32api.SetCursorPos((x, y + 90))
    mouse.click('left')
Exemple #13
0
 def step_click(self):
     self.step = True
     self.program_code.setDisabled(True)
     QMessageBox.warning(
         self, 'Uwaga',
         "Krokowe dzialanie programu. Nacisnij klaiwsz 'w' aby przejsc do nastepnego kroku.",
         QMessageBox.Yes, QMessageBox.Yes)
     text = self.program_code.toPlainText()
     text = text.split('\n')
     for i in range(len(text)):
         self.stop = True
         commands = text[i].split(" ")
         index = commands[0]  # numer instrukcji
         mode = commands[1]  # rozkaz
         if "INT" in mode:
             option = 0
         elif mode == "PUSH" or mode == "POP":
             option = 1
             register = commands[2]
         else:
             option = 2
             register = commands[2].split(",")  # dane
             if '#' in register[1]:
                 register[1] = register[1][1:]
                 address = True
         while len(index) < 3:
             index = '0' + index
         self.program_counter.setText(index)  # wysiwetl numer instrukcji
         ##################################
         if option == 2:
             op1, c1 = self.findReg(register[0])
             if not address:
                 op2, c2 = self.findReg(register[1])
         elif option == 1:
             op1 = self.findReg(register)
         ##################################
         if mode == 'MOV':
             if not address:
                 number = op2.getReg(c2)
                 op1.mov(number, c1)
             else:
                 number = bin(int(register[1]))[2:]
                 while len(number) < 8:
                     number = '0' + number
                 op1.mov(number, c1)
         if mode == 'ADD':
             if not address:
                 number = op2.getReg(c2)
                 number = int(number, 2)
                 op1.add(number, c1)
             else:
                 number = int(register[1])
                 op1.add(number, c1)
         if mode == 'SUB':
             if not address:
                 number = op2.getReg(c2)
                 number = int(number, 2)
                 op1.sub(number, c1)
             else:
                 number = int(register[1])
                 op1.sub(number, c1)
         if mode == "INT1A":
             if hex(int(self.regA.high, 2)) == "0x2":
                 czas = w32.GetSystemTime()
                 hour = self.convertToBCD(czas[4] + 2)
                 minute = self.convertToBCD(czas[5])
                 second = self.convertToBCD(czas[6])
                 self.regC.high = hour
                 self.regC.low = minute
                 self.regD.high = second
             if hex(int(self.regA.high, 2)) == "0x3":
                 hour = self.convertFromBCD(self.regC.high) - 2
                 minute = self.convertFromBCD(self.regC.low)
                 second = self.convertFromBCD(self.regD.high)
                 year = datetime.datetime.now().year
                 month = datetime.datetime.now().month
                 day = datetime.datetime.now().day
                 dayOfWeek = datetime.date.today().weekday()
                 w32.SetSystemTime(year, month, dayOfWeek, day, hour,
                                   minute, second, 0)
             if hex(int(self.regA.high, 2)) == "0x4":
                 czas = w32.GetSystemTime()
                 century = self.convertToBCD(int(str(czas[0])[:2]))
                 year = self.convertToBCD(int(str(czas[0])[2:]))
                 month = self.convertToBCD(czas[1])
                 day = self.convertToBCD(czas[3])
                 self.regC.high = century
                 self.regC.low = year
                 self.regD.high = month
                 self.regD.low = day
             if hex(int(self.regA.high, 2)) == "0x5":
                 hour = datetime.datetime.now().time().hour - 2
                 minute = datetime.datetime.now().time().minute
                 second = datetime.datetime.now().time().second
                 year = self.convertFromBCD(self.regC.low)
                 century = 100 * self.convertFromBCD(self.regC.high)
                 month = self.convertFromBCD(self.regD.high)
                 day = self.convertFromBCD(self.regD.low)
                 dayOfWeek = datetime.date.weekday(
                     datetime.date(century + year, month, day))
                 w32.SetSystemTime(century + year, month, dayOfWeek, day,
                                   hour, minute, second, 0)
             else:
                 print("Nie znaleziono komendy.")
         if mode == "INT10":
             if hex(int(self.regA.high, 2)) == "0x2":
                 x = int(self.regD.high, 2)
                 y = int(self.regD.low, 2)
                 w32.SetCursorPos((x, y))
             else:
                 print("Nie znaleziono komendy.")
         if mode == "INT21":
             if hex(int(self.regA.high, 2)) == "0x1":
                 line = sys.stdin.readline()
                 if len(line) > 1:
                     line = line[0]
                 print(line)
                 kod = bin(ord(line))[2:]
                 while len(kod) < 8:
                     kod = '0' + kod
                 self.regA.low = kod
             if hex(int(self.regA.high, 2)) == "0x2":
                 char = self.regD.low
                 self.regA.low = char
                 char = chr(int(char, 2))
                 sys.stdout.write(char)
             if hex(int(self.regA.high, 2)) == "0x36":
                 temp_dict = {1: 'C:', 2: 'D:', 3: 'E:', 4: 'F:'}
                 temp_dict.setdefault(0, "")
                 ind = int(self.regD.low, 2)
                 test = w32.GetDiskFreeSpace(temp_dict[ind])
                 ra = test[0]
                 rb = test[1]
                 rc = test[2]
                 rd = test[3]
                 if rc >= 256 * 256:
                     rc = 256 * 256 - 1
                 if rd >= 256 * 256:
                     rd = 256 * 256 - 1
                 ra = bin(ra)[2:]
                 while len(ra) < 16:
                     ra = '0' + ra
                 rb = bin(rb)[2:]
                 while len(rb) < 16:
                     rb = '0' + rb
                 rc = bin(rc)[2:]
                 while len(rc) < 16:
                     rc = '0' + rc
                 rd = bin(rd)[2:]
                 while len(rd) < 16:
                     rd = '0' + rd
                 self.regA.high = ra[0:8]
                 self.regA.low = ra[8:16]
                 self.regB.high = rb[0:8]
                 self.regB.low = rb[8:16]
                 self.regC.high = rc[0:8]
                 self.regC.low = rc[8:16]
                 self.regD.high = rd[0:8]
                 self.regD.low = rd[8:16]
             else:
                 print("Nie znaleziono komendy. ")
         if mode == "PUSH":
             self.stack.insert(0, (op1.getFull(), op1))
             self.updateStack(True)
             self.stack_pointer += 1
         if mode == "POP":
             values = self.stack.pop(0)
             value = values[0]
             reg = values[1]
             reg.high = value[0:8]
             reg.low = value[8:16]
             self.stack_pointer -= 1
             self.updateStack()
         self.stack_pointer_view.setText(
             str(self.max_stack - self.stack_pointer))
         self.updateReg()
         while self.stop:
             QCoreApplication.processEvents()
             sleep(0.01)
     buttonReply = QMessageBox.warning(
         self, 'Uwaga', "Zakonczono krokowe dzialanie programu.",
         QMessageBox.Yes, QMessageBox.Yes)
     if buttonReply == QMessageBox.Yes:
         self.program_code.setDisabled(False)
     self.step = False