首页 > 编程语言 >[1037] Python operation of three keys shortcut (pynput)

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

时间:2024-07-22 13:08:34浏览次数:10  
标签:Python three shortcut release Key keyboard press pynput left

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)
AI-generated code. Review and use carefully. More info on FAQ.

This delightful snippet will gracefully slide your active window to the left monitor.

标签:Python,three,shortcut,release,Key,keyboard,press,pynput,left
From: https://www.cnblogs.com/alex-bn-lee/p/18315809

相关文章

  • Python:定期检测断开故障的USB设备并重新初始化实例
    我有一个USB设备,有时会通过USB端口发送串行数据。问题是设备出现故障,有时会无缘无故地断开连接并再次连接到电脑。问题不大,但在这些情况下我需要重新初始化serial.Serial(port)实例,这有点烦人。该设备没有可以从我那里收到的任何命令,我可以验证它是否已连接。我可以......
  • 【校招+社招】华为OD机试 - 拼接URL(Java、JavaScript、Python、C、C++)
    鱼弦:公众号【红尘灯塔】,CSDN博客专家、内容合伙人、新星导师、全栈领域优质创作者、51CTO(Top红人+专家博主)、github开源爱好者(go-zero源码二次开发、游戏后端架构https://github.com/Peakchen)算法概述URL拼接(URL拼接)是指将多个URL组件(方案、主机、端口、路径、查询参......
  • 使用 Google Colab 时,Python 包“datasets”从 virtualenv 目录“site-packages”中消
    我正在使用GoogleColab并尝试创建一个虚拟环境来工作。我的代码是:fromgoogle.colabimportdrivedrive.mount('/content/drive')!pipinstallvirtualenvmyenv_dir='/content/drive/MyDrive/virtual_env/'!virtualenv{myenv_dir}!chmod+x{myen......
  • Python 3 - openpyxl - 按名称迭代列
    使用openpyxl不按数字而是按列标题(ws第一行中的字符串值)迭代列的最简单方法是什么:如下所示:forcellinws.columns['revenue']:print(cell.value)不幸的是,openpyxl不直接支持像ws.columns['revenue']这样按列标题进行迭代。openpyxl......
  • Python selenium 网络抓取 recaptcha
    我想抓取一个网站,但在此之前有一个验证码,我什至使用api获取了数据,并且我还将其注入到网站中,因为网页没有提交按钮,我无法提交。流程是这样的,如果我解决同一网址中的验证码,隐藏的内容将被显示。但它并没有得到解决。我到处都找过了。我找不到解决方案。谁能帮我解决这个问题?......
  • Python 装饰器 详解+案例
    Python装饰器是一种特殊的函数,用于修改其他函数的功能。装饰器可以在不改变原函数代码的情况下,对函数进行增加、修改或者扩展功能。装饰器的语法形式是在函数定义前使用@符号,并在@后面加上装饰器的名称。装饰器函数接受被装饰函数作为参数,并返回一个修改后的函数。impo......
  • 如何在 vercel 部署中路由 python 和 typescript 无服务器函数
    我从一个带有Next.js和Typescript前端以及python后端的全栈应用程序开始。由于我们想在vercel上部署,因此我们将所有后端功能迁移到/api文件夹中的typescript函数中,可通过以下方式访问:fetch('api/**foldername**)问题是我有一个简单的pytorch模型,因此......
  • python中datetime模块
    datetime模块可以更方便的显示日期,并对日期进行计算。datetime模块中常用的类及其功能描述如下:datetime.datetime------>表示日期时间的类(常用)datetime.timedelta------>表示时间间隔的类(常用)datetime.date------>表示日期的类datetime.time------>表示时间的类datetime.......
  • Python - requests
    前言:介绍:安装及验证:使用:连续接口请求:传参方式: 前言:当你上班无聊的时候,你做什么,说实话有人让我写个requests的教程,教程我觉得网上已经有很多教程了,也很全面,我还是不要献丑了介绍:哎,我认为就是一个接口请求的仓库,不过requests属于第三方库,......
  • Python学习计划——2.4列表推导式(List Comprehensions)
    列表推导式是Python的一种简洁且强大的语法,用于生成新的列表。它可以用更少的代码、更清晰的方式来创建列表,特别是在处理简单的循环和条件操作时。1.基本语法列表推导式的基本语法如下:[expressionforiteminiterable]expression:表达式,计算结果用于生成列表的元素。ite......