Windows has a "snap function" that allows you to split the screen into two left and right (four when including the top and bottom) by pressing the Win key and the arrow keys at the same time. This time, I will extend this function with keyhac so that it can snap even at a ratio of 1: 2.
It is recommended for those who want to view windows side by side, but half of them are too small, but it is troublesome to resize them by hand.
(Completed image ↓)
We will write the contents of the function configure
of config.py
.
def configure(keymap):
keymap.replaceKey("(28)", 236) #Assign virtual code 236 to the conversion key
keymap.defineModifier(236, "User1") #Virtual modifier key for conversion key"U1"Use as
def triple_snap(position = "center", Narrow = False):
main_monitor_info = (pyauto.Window.getMonitorInfo())[0]
non_taskbar_area = main_monitor_info[1]
[monitor_left, monitor_top, monitor_right,monitor_bottom] = non_taskbar_area
monitor_width = monitor_right - monitor_left
ratio = 3
if Narrow:
wnd_width = int(monitor_width / ratio)
wnd_pos_table = {
"center": {
"left": wnd_width,
"right": wnd_width * 2,
},
"left": {
"left": monitor_left,
"right": wnd_width,
},
"right": {
"left": wnd_width * 2,
"right": monitor_right,
},
}
else:
wnd_width = int(monitor_width / ratio) * 2
wnd_pos_table = {
"center": {
"left": int(monitor_width / ratio / 2),
"right": int(monitor_width / ratio / 2) + wnd_width,
},
"left": {
"left": monitor_left,
"right": wnd_width,
},
"right": {
"left": int(monitor_width / ratio),
"right": monitor_right,
},
}
wnd_area = wnd_pos_table[position]
rect = [wnd_area["left"], monitor_top, wnd_area["right"], monitor_bottom]
wnd = keymap.getTopLevelWindow()
if list(wnd.getRect()) == rect:
wnd.maximize()
else:
if wnd.isMaximized():
wnd.restore()
wnd.setRect(rect)
for k in [
("U1-M" , lambda: triple_snap("center", False)),
("S-U1-H", lambda: triple_snap("left" , False)),
("S-U1-L", lambda: triple_snap("right" , False)),
("C-U1-H", lambda: triple_snap("left" , True)),
("C-U1-L", lambda: triple_snap("right" , True)),
("C-U1-M", lambda: triple_snap("center", True)),
("U1-H" , "Win-Left"),
("U1-L" , "Win-Right"),
]:
keymap_global[k[0]] = k[1]
Use the conversion key and M to bring the window to the center of the screen with 2/3 of the monitor width. Press the same key again to maximize.
If you hold down Ctrl at the same time, the width will be reduced to 1/3.
Assign normal left / right snaps to the conversion keys and H / L, and hold Shift to snap 2/3 and Ctrl to 1/3 width.
(In the first place, if you can make it multi-monitor, everything will be solved.)
Recommended Posts