Linux桌面操作 鼠标操作 print("n> >>>>>>>鼠标移动") desktop.movemouse(100, 200) Move to x, y coordinates desktop.wait(1000) Wait for 1 second print("n> >>>>>>>右键单击") desktop.rightclick(x100, y200) desktop.wait(1000) Wait for 1 second 键盘操作 print("n> >>>>>>>输入文本") desktop.write("Hello, world!") Default: chunksize25, delayinms75 desktop.write("Fast typing!", chunksize50, delayinms25) Faster typing print("n> >>>>>>>键盘按下") Press keys desktop.press("enter") desktop.press("space") desktop.press("backspace") desktop.press(["ctrl", "c"]) Key combination 窗口控制 print("n> >>>>>>>获取当前窗口id") Get current (active) window ID windowid desktop.getcurrentwindowid() print(f"获取当前窗口id:{windowid}") print("n> >>>>>>>获取当前窗口标题") Get window title title desktop.getwindowtitle(windowid) print(f"获取当前窗口标题:{title}") 文件操作 print("n> >>>>>>>写入文件") desktop.files.write("/home/user/index.js", "console.log('hello')", user"user") print("n> >>>>>>>读取文本文件") resulttext desktop.files.read("/home/user/index.js", "text", user"user") print(f"读取到文件内容text格式内容是:{resulttext}") print("n> >>>>>>>删除文件") desktop.files.remove("/home/user/index.js", user"user") print("n> >>>>>>>截图") image desktop.screenshot() with open("screenshot.png", "wb") as f: f.write(image) 关闭 desktop.stream.stop() desktop.kill() if name "main": main()
来自: