Created
July 31, 2017 08:54
-
-
Save hisasann/5c861191c70ab8b9cd43757de5f709e5 to your computer and use it in GitHub Desktop.
windows上で輝度を変更するコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Management; | |
namespace DeviceManager.Brightness | |
{ | |
class BrightnessController | |
{ | |
ManagementClass WmiMonitorBrightnessMethods = new ManagementClass("root/wmi", "WmiMonitorBrightnessMethods", null); | |
// via http://home.a00.itscom.net/hatada/csharp/lcd01.html | |
// https://stackoverflow.com/questions/18083982/how-to-query-getmonitorbrightness-from-c-sharp | |
// https://stackoverflow.com/questions/8194006/c-sharp-setting-screen-brightness-windows-7 | |
// https://msdn.microsoft.com/ja-jp/library/system.management.managementscope(v=vs.110).aspx | |
public void SetBrightness(int level) | |
{ | |
foreach (ManagementObject mo in WmiMonitorBrightnessMethods.GetInstances()) | |
{ | |
ManagementBaseObject inParams = mo.GetMethodParameters("WmiSetBrightness"); | |
inParams["Brightness"] = level; // 輝度を level % に | |
inParams["Timeout"] = 5; // 操作のタイムアウトを 5 秒にセット | |
mo.InvokeMethod("WmiSetBrightness", inParams, null); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment