Comments (8)
Did some research to find a solution:
It can be retrieved using WMI (Windows Management Instrumentation) with this operation`from Windows PowerShell (documentation):
Get-Ciminstance -Namespace root/WMI -ClassName WmiMonitorBrightness
Returns a structure with a property named "CurrentBrightness" that goes from 0 to 100 (uint8).
Only runs on Vista or higher.
Setting the brightness can be done with (documentation):
$monitor = Get-WmiObject -Namespace root\wmi -Class WmiMonitorBrightnessMethods
$monitor.wmisetbrightness(0, 25)
There is additionally a Windows API (GetMonitorBrightness) that gives the same, also only runs on Vista or higher:
https://msdn.microsoft.com/en-us/library/ms775205.aspx
I presume this is the way NirCmd (used by Brightness) does it's set operation:
http://www.nirsoft.net/vc/change_screen_brightness.html
from brightness.
Super research @sondreb! :)
Get-Ciminstance -Namespace root/WMI -ClassName WmiMonitorBrightness
Is there a way to do this from cmd.exe? I know you can use WMI like a normal command.
Only runs on Vista or higher.
That's not a problem. We don't care about supporting WinXP.
from brightness.
Here is code to make it work. This WMI client supports Linux as well, so it might be an option to use WMI for both Windows and Linux:
var WmiClient = require('wmi-client');
var wmi = new WmiClient({
host: 'localhost',
namespace: '\\\\root\\WMI' // Important, defaults to '\\root\cimv2'
});
// Doing select ONLY on CurrentBrightness as oppose to * or multiple columns, returns empty array!?
wmi.query('SELECT * FROM WmiMonitorBrightness', function (err, result) {
// There might be multiple monitors... I presume that's why it returns an array?
var currentBrightness = result[0].CurrentBrightness;
console.log('CurrentBrightness: ' + currentBrightness + "%.");
});
from brightness.
@sondreb Awesome! Interested in doing a pull request?
from brightness.
This is great @sondreb, PR is super welcome!
from brightness.
@sindresorhus / @kevva I will do a PR, just wanted to mention it here so nobody else does it and duplicates efforts. Will try to get it done tonight or tomorrow. I might do it in two phases, first is adding read support (for Windows) and then perhaps consider using WMI to set brightness as well.
from brightness.
There appears to be a considerable delay when executing powershell.exe from node.js, the same is true from a regular cmd.exe in Windows. I had a working solution using PowerShell, but I changed to wmic which is a command tool for WMI operations on Windows (used by wmi-client package as well).
wmic solution is not working, as I'm unable to find the proper syntax for parameters. I got it almost complete, but until then, nircmd can be used for setting. Should be updated as soon as I find a solution for wmic, as that should probably be better and reduce dependencies a little bit. Already spent the whole day investigating this thing.
Made a PR and additionally I made a win-brightness package. I hope it was OK I took some code from you @kevva, added some links in the readme on the repo.
At least I learnt a lot more about WMI, wmic and PowerShell...
from brightness.
Fixed in 676555e. Thank you very much for this @sondreb! Great work :).
from brightness.
Related Issues (16)
- Interactive CLI HOT 8
- Broken in macOS 10.12.4 HOT 1
- (node:8987) UnhandledPromiseRejectionWarning: Unhandled promise rejectio n (rejection id: 1): Error: No backlight device found HOT 5
- Any way to prevent using `sudo`? HOT 5
- Listen to outside brightness changing
- ios support
- Brightness resets after 30 seconds in MacOS
- Not working on linux.
- Window not supported HOT 1
- Crash when given no arguments (OS X 10.10.3, node.js 0.12.2 via brew) HOT 1
- Windows support
- catch the errors in cli HOT 1
- No effect in brightness HOT 9
- Operating systems and computer support? HOT 3
- Weird initial output of interactive interface
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brightness.