spyoungtech / ahk

Python wrapper for AutoHotkey with full type support. Harness the automation power of AutoHotkey with the beauty of Python.
MIT License
887 stars 66 forks source link

ahk to arrange windows up and down #268

Closed P-Rainbow closed 8 months ago

P-Rainbow commented 8 months ago

Below code is to arrange 2 windows up and down, each to occupy half screen.

It works well in a computer. However the same code, in another computer, it only activates both windows, but doesn't arrange them in the wanted sizes and positions.

Can you please help me? Thank you.

from ahk import AHK

ahk = AHK()

import ctypes, time
user32 = ctypes.windll.user32
screensize = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)

screen_width = screensize[0]
screen_height = screensize[1]

window_up = ahk.find_window(title='TEM') # Find the opened window
window_up.move(x=0, y=0, width=screen_width, height=screen_height/2)                # up & down
window_up.activate()

window_down = ahk.find_window(title='Document1') # Find the opened window
window_down.move(x=0, y=screen_height/2, width=screen_width, height=screen_height/2)  # up & down
window_down.activate()
spyoungtech commented 8 months ago

Hmm. When I try the code, it works as expected for me. I'm not sure why just changing computers would cause this to not work.

but doesn't arrange them in the wanted sizes and positions.

Can you elaborate on the actual behavior that is does do? Does it not move the windows at all? Does it move them, but in the wrong dimensions? Or something else? Are you using the same applications on both computers?

One thought might be that screensize represents the primary display only, as I understand it. Perhaps the other computer has multiple displays?

P-Rainbow commented 8 months ago

@spyoungtech thank you for the vary detailed and caring follow-up.

I tried it a few times and seemed found the cause is the Scale and Layout of (computer's) Display Settings.

When the Scale and Layout set to 100%, it works fine. When it is set to 150% (Recommended), the Windows arranged in a smaller scale, as shown in the screenshot.

789

Picture1

spyoungtech commented 8 months ago

Interesting. Glad you found out what seems to be causing that. Some more context can be found in the autohotkey documentation regarding this. I also found this forum post and this forum post which may elaborate further.

Though the documentation mentions some workarounds, it's not immediately clear to me how to apply them in this context.

P-Rainbow commented 8 months ago

@spyoungtech thanks again!