Python 屏幕亮度调节

核心代码:

方法一:

import wmi
c = wmi.WMI(namespace='root\WMI')

a = c.WmiMonitorBrightnessMethods()[0]
a.WmiSetBrightness(Brightness=80, Timeout=500) # Brightness:亮度

使用wmi实现了亮度调节,但部分电脑可能会出现错误。

                                                                        安装wmi

pip install wmi

如果嫌下载太慢或者下载出现问题,可以使用国内的pypi网站下载(如:清华大学)

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple wmi

以下是部分电脑会出现的错误,如果出现其他错误,请参考Microsoft WMI 错误常量

 方法二:

此方法简单明了,且不会发生错误,推荐使用本方法

import screen_brightness_control as sbc
sbc.set_brightness(0)

                                                安装screen_brightness_control

pip install screen-brightness-control

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple screen-brightness-control

所以,我们可以玩一点刺激的:

实现闪烁(把亮度从100调为0,再调为100)

import screen_brightness_control as sbc
import time

while True:
    sbc.set_brightness(0)
    time.sleep(1)
    sbc.set_brightness(100)

如果要边执行别的代码边闪烁,可以使用多线程:

import screen_brightness_control as sbc
import time
import threading

def sb(): # 定义线程执行的函数
    while True:
    sbc.set_brightness(0)
    time.sleep(1)
    sbc.set_brightness(100)

threading.Thread(target=sb).run() # target:指定的函数, run():运行线程

以上就是使用Python实现屏幕闪烁的代码,喜欢本文章可以加个关注,想要了解病毒可以去看这位博主的博客:Marshmello的博客,最后,提醒大家:使用病毒是非常危险且不道德的行为,本文章只限编程爱好者参考,如果因本文章中的代码而违反规定或法律,请由自己承担!

Gamma Manager is based on Gamma Slider control. This control allows to change gamma monitor on most graphic cards. The goal for this project is very simple and control is for VC6 & VC7. The other day I downloaded a N64 emulator but the screen was so black that I did not see anything. I had thus to find this solution to lighten my screen. I know that the tools of my video chart make it possible to change gamma of my screen, but it is faster with this tool. Implementation The implementation of this slider control is very easy. Import GammaSlider.h and GammaSlider.cpp into your project. Include reference to the class control. Add slider control on a form. Use ClassWizard to declare variable name derived from CGammaSlider control. That's it, enjoy! Under the hood Windows provides two APIs GetDeviceGammaRamp/ SetDeviceGammaRamp to perform gamma correction. In fact we need to have a 3 dimensional buffer of 256 WORD to manipulate gamma correction. To change gamma, it is necessary to change the RGB value of each color contained in the buffer by a float factor between 0.0 and 2.0. Example We need to save current gamma for future restore. Collapse Copy CodeWORD m_RampSaved[256*3]; if (!GetDeviceGammaRamp(::GetDC(NULL), m_RampSaved)) { TRACE("WARNING: Cannot initialize DeviceGammaRamp.\n"); }To change gamma, cycle into ramp buffer and change RGB color where Gamma is the float factor. Collapse Copy CodeWORD ramp[256*3]; for( int i=0; i<256; i++ ) { ramp[i+0] = ramp[i+256] = ramp[i+512] = (WORD)min(65535, max(0, pow((i+1) / 256.0, Gamma) * 65535 + 0.5)); } SetDeviceGammaRamp(::GetDC(NULL), ramp);Now to trap slider control message, we need to use a special message ON_WM_HSCROLL_REFLECT() that can provide message to be dispatched into control class itself.
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值