![](/img/trans.png)
[英]Python Win32API SendMessage win32con WM_SETTEXT only works once
[英]Win32Api Python .SetCursorPos(x,y) how works?
你好我有这个代码
import win32api
from tkinter import *
def Cursor():
win32api.SetCursorPos(10,10)
root = Tk()
root.geometry("500x500")
root.title("")
root.configure(background="#262626")
PlayButton = Button(root, text="Cursor", command=Cursor ).pack()
root.mainloop()
他给了我这个错误
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1533, in __call__
return self.func(*args)
File "C:\Users\filippo\Desktop\Win32.py", line 5, in Cursor
win32api.SetCursorPos(10,10)
TypeError: SetCursorPos() takes exactly 1 argument (2 given)
为什么? 他告诉我我必须输入 1 个参数,但 x 和 y 轴应该是 2
将坐标作为元组传递:
def Cursor():
win32api.SetCursorPos((10,10))
import win32api, win32con
pos_x = 1000
pos_y = 600
for x in range(pos_x):
subt = int(pos_x/50)
win32api.mouse_event(win32con.MOUSE_MOVED, 2, 0)
if (x+1) == pos_x - subt:
break
for x in range(pos_y):
subt = int(pos_y/50)
win32api.mouse_event(win32con.MOUSE_MOVED, 0, 2)
if (x+1) == pos_y - subt:
break
如果您的屏幕尺寸为 1366x768,则在 win32api 中的位置是不同的,因此在 win32api 中,尺寸为 3000x1687。 我尝试使用 win32api 将光标放在给定位置。 我使用 win32api 是因为我们可以控制 Minecraft 等游戏上的光标。警告:- 此代码在这里不是 100% 准确的 1-2px 加或减。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.