Last active
September 28, 2019 17:29
-
-
Save vasily-v-ryabov/f6c6f4d94fe313be8236 to your computer and use it in GitHub Desktop.
pywinauto example for drag-n-drop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# requirements: Python 2.7 or 3.4, pyWin32, pywinauto 0.5.0+ | |
# download the repo: https://github.com/pywinauto/pywinauto | |
# place this script to repo root folder | |
import sys, os | |
os.chdir(os.path.join(os.getcwd(), os.path.dirname(sys.argv[0]))) # running at repo root folder | |
import pywinauto | |
mfc_samples_folder = os.path.join( | |
os.path.dirname(sys.argv[0]), r"apps\MFC_samples") | |
if pywinauto.sysinfo.is_x64_Python(): | |
mfc_samples_folder = os.path.join(mfc_samples_folder, 'x64') | |
app = pywinauto.Application.start(os.path.join(mfc_samples_folder, u"CmnCtrl1.exe")) | |
tree = app.Common_Controls_Sample.TreeView.WrapperObject() | |
birds = tree.GetItem(r'\Birds') | |
dogs = tree.GetItem(r'\Dogs') | |
# drag-n-drop without focus on the window | |
#tree.DragMouse("left", birds.Rectangle().mid_point(), dogs.Rectangle().mid_point()) | |
# most natural drag-n-drop (with real moving mouse, like real user) | |
tree.DragMouseInput("left", birds.Rectangle().mid_point(), dogs.Rectangle().mid_point()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment