[PYTHON] Split screen into 3 with keyhac

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 ↓) fig1.png

code

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]

Execution image

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.

fig2.png

If you hold down Ctrl at the same time, the width will be reduced to 1/3. fig3.png

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

Split screen into 3 with keyhac
screen and split screen with python and ssh login to remote server
Screen switching / screen transition with Tkinter
Split PDF into arbitrary pages
Create screen scroll with Pythonista + scene
[Blender] Split Blender script into multiple files
Get web screen capture with python