Skip to content

Instantly share code, notes, and snippets.

@hisasann
Created July 31, 2017 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hisasann/5c861191c70ab8b9cd43757de5f709e5 to your computer and use it in GitHub Desktop.
Save hisasann/5c861191c70ab8b9cd43757de5f709e5 to your computer and use it in GitHub Desktop.
windows上で輝度を変更するコード
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