alex_bn_lee

导航

[1037] Python operation of three keys shortcut (pynput)

The shortcut of win + shift + left does not work well in pyautogui, but it works well in pynput.

Moving the Active Window to a Different Monitor: You’re right; PyAutoGUI doesn’t directly support moving windows across monitors with the elegance of a swan gliding across a lake. But fear not! We have a workaround. Instead of PyAutoGUI, let’s enlist the help of another Python library called pynput. Here’s how you can move that window like a digital nomad:

from pynput.keyboard import Key, Controller

keyboard = Controller()

# Press the Windows key (also known as the meta key)
keyboard.press(Key.cmd)
keyboard.press(Key.shift)
keyboard.press(Key.left)
keyboard.release(Key.cmd)
keyboard.release(Key.shift)
keyboard.release(Key.left)

This delightful snippet will gracefully slide your active window to the left monitor. 🌟 Feel free to replace Key.left with Key.right if you want to send it on a journey to the right monitor instead.

posted on 2024-07-22 12:57  McDelfino  阅读(1)  评论(0编辑  收藏  举报