Python win32api.SetCursorPos双屏幕问题

Python win32api.SetCursorPos双屏幕问题,python,winapi,wxpython,mousemove,Python,Winapi,Wxpython,Mousemove,我正在尝试创建一个简单的程序,它将根据您的选择,每x秒单击一次特定的坐标,如果您需要单击左屏幕或右屏幕。我这里的问题是,随光标移动的win32api.SetCursorPos没有移动到辅助屏幕(在我的例子中就是这样)。它停留在主屏幕上 我的代码还有一个问题,当按下GUI中的退出按钮时,窗口将关闭,但程序仍在后台运行。我正在使用self.Destroy()函数终止所有进程 谢谢你的建议 这是我的密码: import time import pyautogui import wx import th

我正在尝试创建一个简单的程序,它将根据您的选择,每x秒单击一次特定的坐标,如果您需要单击左屏幕或右屏幕。我这里的问题是,随光标移动的win32api.SetCursorPos没有移动到辅助屏幕(在我的例子中就是这样)。它停留在主屏幕上

我的代码还有一个问题,当按下GUI中的退出按钮时,窗口将关闭,但程序仍在后台运行。我正在使用self.Destroy()函数终止所有进程

谢谢你的建议

这是我的密码:

import time
import pyautogui
import wx
import threading
import sys
import win32api

class bucky(wx.Frame):

    def __init__(self,parent,id):
        self.positionx = ""
        self.positiony = ""
        wx.Frame.__init__(self,parent,id,'AutoClick 2.0', size=(300,200))
        panel=wx.Panel(self)
        self.buttonpos=wx.Button(panel,label="Left Screen",pos=(30,10),size=(80,40))
        self.buttonpos2=wx.Button(panel,label="Right Screen",pos=(180,10),size=(80,40))
        self.button=wx.Button(panel,label="Start",pos=(120,90),size=(60,30))
        self.button2=wx.Button(panel,wx.ID_EXIT,label="Exit",pos=(120,120),size=(60,30))
        self.Bind(wx.EVT_BUTTON, self.action, self.button)
        self.Bind(wx.EVT_BUTTON, self.closebutton, self.button2)
        self.Bind(wx.EVT_BUTTON, self.position, self.buttonpos)
        self.Bind(wx.EVT_BUTTON, self.position, self.buttonpos2)
        self.Bind(wx.EVT_CLOSE, self.closewindow)


    def position(self, event):
        label = event.GetEventObject().GetLabel()
        if label == "Left Screen":
            self.positionx = 1640
            self.positiony = 183
            self.buttonpos.Disable()
            self.buttonpos2.Enable()
        elif label == "Right Screen":
            self.positionx = 3308
            self.positiony= 186
            self.buttonpos.Enable()
            self.buttonpos2.Disable()

    def closebutton(self,event):
        self.Destroy()

    def closewindow(self,event):
        self.Destroy()

    def action(self,event):
        self.button.Disable()
        def callback():
            while 1:
                pos = pyautogui.position()
                time.sleep(10)
                pos1 = pyautogui.position()
                if (pos1[0] == pos[0]) and (pos1[1] == pos[1]):
                    win32api.SetCursorPos((self.positionx, self.positiony))
                    pyautogui.click()
                else:
                    pass
        t = threading.Thread(target=callback)
        t.start()

if __name__=='__main__':
    app=wx.PySimpleApp()
    frame=bucky(parent=None,id=1)
    frame.Show()
    app.MainLoop()
编辑:问题已解决。感谢您的帮助。

看这篇文章,我认为辅助监视器的x坐标只是添加到主监视器的分辨率中(例如,如果您有两个1920x1080监视器,则第二个监视器的中间位置将为2880520)

尝试使用
(win32api.GetSystemMetrics(MONITOR\u NUMBER)
来查看差异是如何表示的。

看看这篇文章,我认为辅助监视器的x坐标只是添加到主监视器的分辨率中(例如,如果您有两个1920x1080监视器,第二个监视器的中间将位于2880520)


尝试使用
(win32api.GetSystemMetrics(监视器编号)
查看差异是如何表现的。

谢谢你的回答。实际上这里有一些更多信息:屏幕大小:3360 x 1050,有两个监视器。你可以看到我定义坐标self.positionx=1640 self.positiony=183或self.positionx=3308 self.positiony=186谢谢你的回答。实际上这是some更多信息:屏幕尺寸:3360 x 1050,有两个监视器。您可以看到Im定义坐标self.positionx=1640 self.positiony=183或self.positionx=3308 self.positiony=186