ubuntu 热键设置

The traditional way of turning your monitor off via a hotkey has been broken for a few versions now. A pretty simple Python script can bring that functionality back reliably and efficiently.

通过热键关闭显示器的传统方式现在已被打破。 一个非常简单的Python脚本可以可靠,有效地恢复该功能。

The old way of turning off you monitor was through the xset command:

关闭监视器的旧方法是通过xset命令:

xset dpms force off

xset dpms强制关闭

There are a few variations on that, but since Ubuntu Karmic (9.10), it’s been broken. Some of the system calls apparently don’t get along well with this command, causing the screen to wake up after about a minute. After being annoyed at this for quite some time, I found a few solutions on the Ubuntu Forums. Running this command in a loop seems CPU intensive, and there isn’t a very elegant way to escape it. Thankfully, one user, nxmehta, found a solution utilizing a simple Python script, and it works on everything from Karmic to Natty.

有一些变化,但是自从Ubuntu Karmic(9.10)起,它就被破坏了。 某些系统调用显然与该命令不兼容,导致屏幕在大约一分钟后唤醒。 在对此烦恼了一段时间之后,我在Ubuntu论坛上找到了一些解决方案。 循环运行此命令似乎会占用大量CPU,并且没有一种非常优雅的方法可以对其进行转义。 值得庆幸的是, 一个用户nxmehta找到了一个使用简单Python脚本的解决方案,该解决方案适用于从Karmic到Natty的所有内容。

First of all, you need to have a few dependencies, so open up a terminal and enter the following command:

首先,您需要具有一些依赖性,因此打开一个终端并输入以下命令:

sudo apt-get install python python-xlib

须藤apt-get install python python-xlib

This will install the python and python-xlib packages if they aren’t installed already. Next, open up Text Editor (gedit) and copy/paste the following text:

如果尚未安装python和python-xlib软件包,则将安装它们。 接下来,打开文本编辑器(gedit)并复制/粘贴以下文本:

#!/usr/bin/python
import time
import subprocess
from Xlib import X
from Xlib.display import Display
display = Display(':0')
root = display.screen().root
root.grab_pointer(True,
X.ButtonPressMask | X.ButtonReleaseMask | X.PointerMotionMask,
X.GrabModeAsync, X.GrabModeAsync, 0, 0, X.CurrentTime)
root.grab_keyboard(True,
X.GrabModeAsync, X.GrabModeAsync, X.CurrentTime)
subprocess.call('xset dpms force off'.split())
p = subprocess.Popen('gnome-screensaver-command -i'.split())
time.sleep(1)
while True:
print display.next_event()
p.terminate()
break
#!/usr/bin/python
import time
import subprocess
from Xlib import X
from Xlib.display import Display
display = Display(':0')
root = display.screen().root
root.grab_pointer(True,
X.ButtonPressMask | X.ButtonReleaseMask | X.PointerMotionMask,
X.GrabModeAsync, X.GrabModeAsync, 0, 0, X.CurrentTime)
root.grab_keyboard(True,
X.GrabModeAsync, X.GrabModeAsync, X.CurrentTime)
subprocess.call('xset dpms force off'.split())
p = subprocess.Popen('gnome-screensaver-command -i'.split())
time.sleep(1)
while True:
print display.next_event()
p.terminate()
break

Save your file somewhere with a proper name. I stuck mine in ~/bin/screen_off.sh with the rest of my scripts.

用适当的名称保存文件。 我将其余的脚本卡在〜/ bin / screen_off.sh中。

Next, right-click the file and go to Properties.

接下来,右键单击该文件,然后转到“属性”。

Under the Permissions tab, be sure “Allow executing file as program” is checked. Click Close.

在“权限”选项卡下,确保选中“允许以程序方式执行文件”。 单击关闭。

Now you can assign it to any keyboard shortcut! I like to set mine to Caps Lock, so I had to disable that key first. You can do that by going to Keyboard > Layouts > Options.

现在,您可以将其分配给任何键盘快捷键! 我想将我的密码设置为Caps Lock,因此必须先禁用该键。 您可以通过转到键盘>布局>选项来实现。

Here, choose “Caps Lock is disabled” under Caps Lock key behavior.

在这里,请选择Caps Lock键行为下的“ Caps Lock已禁用”。

To assign this script to a keyboard shortcut, open up Keyboard Shortcuts preferences.

要将此脚本分配给键盘快捷键,请打开“键盘快捷键”首选项。

Click Add, give the shortcut a name, and the command will just be the location of the script. Click Apply, then click under shortcut to set it. If you disabled Caps Lock, you’ll see it listed as “VoidSymbol” but it will work without a hitch.

单击“添加”,为快捷方式命名,该命令将只是脚本的位置。 单击“应用”,然后在快捷方式下单击以进行设置。 如果您禁用了Caps Lock,您会看到它列为“ VoidSymbol”,但可以正常使用。

This has been bugging me for quite some time, and the solution was a bit tough to find what with all of the complaints floating around. Hopefully this will help you conserve your laptop battery.

这已经困扰了我很长时间了,解决方案很难找到所有抱怨四起的东西。 希望这可以帮助您节省笔记本电脑的电池。

翻译自: https://www.howtogeek.com/61836/how-to-turn-off-your-monitor-with-a-hotkey-in-ubuntu/

ubuntu 热键设置

ubuntu 热键设置_如何在Ubuntu中使用热键关闭显示器相关推荐

  1. ubuntu 如何关闭离线模式_如何在macOS中打开或关闭Mac暗黑模式

    苹果在macOS Mojave中为Mac引入了暗模式.暗模式是系统级别的设置,可与Mac随附的所有应用一起使用.第三方应用也可以选择使用暗黑模式.暗黑模式使您更轻松地专注于工作,并且对眼睛也很容易.装 ...

  2. ubuntu四个屏幕设置_如何在 Linux 中为每个屏幕设置不同的壁纸

    如果你想在 Ubuntu 18.04 或任何其他 Linux 发行版上使用 GNOME.MATE 或 Budgie 桌面环境在多个显示器上显示不同的壁纸,这个小工具将帮助你实现这一点. 多显示器设置通 ...

  3. ubuntu 命令卡住_如何在Ubuntu系统中重置root密码

    IT服务圈儿 有温度.有态度的IT自媒体平台 经授权转自公众号:良许Linux(ID:liangxuxiansheng) 很多人有个问题,就是喜欢把密码设置得很长很复杂,结果谁也没防住,却成功防住了自 ...

  4. ubuntu 麦克风录音_如何在Ubuntu中测试麦克风

    如果您使用的是系统的内置麦克风或外接麦克风,请务必测试您的声音是否通过系统.仅当系统正在读取麦克风声音作为输入时,它才能进一步处理它并在任何应用程序中使用它. 在本文中,我们将介绍如何在Ubuntu上 ...

  5. ubuntu添加路由_如何在Ubuntu,Linux中添加新路由?

    ubuntu添加路由 I have a box with Ubuntu Linux and I want to add a new route to my box. Because I want to ...

  6. ubuntu添加面板_如何在Ubuntu的顶部面板中添加天气信息

    ubuntu添加面板 Modern operating systems offer weather information out-of-the-box. There's Windows 10's w ...

  7. ubuntu合并终端_如何在Ubuntu中安装多个终端以及更改默认终端

    终端是任何Linux系统的关键部分.它允许您通过shell访问Linux系统.虽说现在的Linux发行版,比如Ubuntu,CentOS等已经基本上可以采用GUI来完成绝大部分一般性的任务.但是,终端 ...

  8. ubuntu 删除路由_如何在Ubuntu Linux中删除路由?

    ubuntu 删除路由 I have some route in my routing table. But I want to delete one route from routing table ...

  9. ubuntu ftp服务器_如何在Ubuntu上安装FTP服务器?

    ubuntu ftp服务器 In this tutorial, let's learn how to install FTP server on Ubuntu. FTP or File Transfe ...

最新文章

  1. 值得收藏!基于激光雷达数据的深度学习目标检测方法大合集(上)
  2. opengl 深度详解_一步步学OpenGL(1) -《打开一个窗口》
  3. [ATF]-ATF的RT_SVC的详解(runtime service)
  4. python 字符串操作_python中字符串的常见操作(一)
  5. boost::units::absolute相关的测试程序
  6. 风险平价策略python代码_风险平价组合(risk parity)理论与实践
  7. linux idea 权限,Linux下idea由于缺少相关权限导致的tomcat ERROR
  8. 如何禁用 ASP.NET 网站的所有的 浏览器缓存 ?
  9. JAVA反射修改常量,以及其局限
  10. 如何在 Ubuntu 14.04 和 12.04 上测试 systemd
  11. 如何摇晃一瓶水使其核聚变?
  12. [JDBC] Kettle on MaxCompute 使用指南
  13. angularjs 指令详解
  14. c语言 turbo,C语言Turbo C 2.0内容介绍
  15. 数学建模论文常用LaTeX代码(2021美赛)
  16. 在VS中如何设置自动换行
  17. 从零开始搭建博客Hexo-Node-Git搭建博客
  18. Activiti设置流程发起人用户信息
  19. 如何让计算机桌面自动更换,怎样让电脑的桌面自动变换即自动更换桌面背景
  20. 【Gulimall】Spring Cloud:spring-cloud-gateway、spring-cloud-openfeign,Alibaba的注册+配置中心Nacos

热门文章

  1. LeetCode141:判断链表是否有环
  2. Adobe Dreamweaver CS5 adobe acrobat x pro 序列号
  3. 贪吃蛇java代码_java实现贪吃蛇的代码实例
  4. 手动变速箱的基本工作原理
  5. TensorFlow 模型和权重的保存及预测
  6. vue生命周期函数可以操作dom_vue生命周期钩子函数
  7. 解决Hyper-V虚拟机监控程序未运行
  8. Win7一键备份、还原有门道
  9. ICLR 2023 | 首个3D人像视频生成模型!仅需1张2D人像,眨眼、口型都能改变
  10. IT战争:谷歌、苹果、Facebook及亚马逊的四国演义