-
Hi have two monitors, I would like to resize the window so it is in What I did at the moment was use AutoHotkey Window Spy to copy the X,Y values from there. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hmm. Yeah. Similar ideas have been discussed at some length in #85 -- though, I'm not 100% confident in my ability to correctly deal with all monitor scenarios and how reliable that could be. So, for now, the exercise is left to the user, as is the case in AutoHotkey. If AutoHotkey adds an API for this, it will be added in the wrapper. But if someone is motivated to create the functionality, it could perhaps be a good project for an extension package. And there's always room for successful extension projects to be featured in the readme :) Something I do want to provide in the future is a rough analog to Window Spy, which may also be another extension use case. |
Beta Was this translation helpful? Give feedback.
-
I used the import screeninfo
import ctypes
from ctypes import wintypes
user32 = ctypes.WinDLL('user32', use_last_error=True)
def monitor_xy(x: int, y: int, monitor=0) -> tuple[int, int]:
monitors = screeninfo.get_monitors()
if monitor >= len(monitors):
raise ValueError(
f"Monitor index {monitor} is out of range. There are only {len(monitors)} monitors."
)
return (x + monitors[monitor].x, y + monitors[monitor].y)
def one_note() -> None:
one_note_ahk_title = "ahk_exe ONENOTE.EXE"
(x, y) = monitor_xy(0, 0, monitor=1)
window =ahk.win_get(one_note_ahk_title)
if not user32.MoveWindow(int(window.id), x, y, 1920, 2100, True):
raise ctypes.WinError(ctypes.get_last_error())
ahk.win_activate(one_note_ahk_title) |
Beta Was this translation helpful? Give feedback.
I used the
screeninfo
library and the raw Win32 API to move the window