Last active
January 24, 2019 18:57
-
-
Save stephenmm/f518ba8d2dcef015365805ef23b9093f to your computer and use it in GitHub Desktop.
Example of how to use AutoIt to automate screen positioning... Actually, python calling AutoIt and the start of using windows DLLs directly!
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
#! python | |
# To run this double click it in Windows File Explorer | |
# Notes: | |
# Some interesting reading on autoit functionality direclty from windows DLLs: https://stackoverflow.com/questions/23768184/programmatically-rotate-monitor | |
# Functions for win32api http://timgolden.me.uk/pywin32-docs/contents.html | |
# Directly calling the DLLs w/ ctypes: https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getsystemmetrics | |
import time | |
import win32com.client | |
import win32api | |
import win32con | |
import ctypes | |
# Simple ctypes examples: | |
ctypes.windll.user32.GetSystemMetrics(78) | |
ctypes.windll.user32.GetSystemMetrics(79) | |
def getNbrDisplays(): | |
return ctypes.windll.user32.GetSystemMetrics(80) | |
class VirtualDisplay(): | |
'''At some point make this smart and detect the values''' | |
upper_left_display_x = -516 | |
upper_left_display_y = -1200 | |
upper_left_display_width = 3850 | |
upper_left_display_height = 1200 | |
vd=VirtualDisplay() | |
# The real functionality to bring up vncviewer and position it correctly. (This is the first working attempt so probably rough around the edges): | |
Auto=win32com.client.Dispatch("AutoItX3.Control") | |
Auto.AutoItSetOption("SendKeyDelay", 2) | |
Auto.Opt("WinTitleMatchMode", 2) # 1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase | |
Auto.Send("#r") # Start windows command prompt | |
Auto.WinWait("Run", "", 10) | |
Auto.Send('C:\Program Files\TigerVNC\\vncviewer.exe servername.mywork.com:1{Enter}') | |
Auto.WinWait("[TITLE:VNC authentication]", "", 10) | |
Auto.Send("psswrd{ENTER}") | |
Auto.WinWait("[TITLE:servername]", "", 10) | |
# size the window slightly smaller than the display to allow us to see apps behind it | |
Auto.WinMove( "[TITLE:servername]", "" \ | |
,vd.upper_left_display_x \ | |
,vd.upper_left_display_y \ | |
,vd.upper_left_display_width \ | |
,vd.upper_left_display_height - 10 \ | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment