Screen Power Mode
Turn on or off the device screen.
Different from injecting a power key event, this command only affects the physical screen, it doesn't lock the device.
If cleanup: true (the default value) is set in the ScrcpyOptions, Scrcpy server will restore the screen state to Normal on exit. Pressing the physical power button twice usually turns the screen back on.
Caveats
- On some LCD screens, turning off the screen only turns off the backlight, the screen is still visible under strong light.
- Some in-display fingerprint sensors use the screen to illuminate the finger, turning off the screen will cause them to stop working.
- Most apps are unaware of the screen state, but some apps may behave differently when the screen is off, it has been reported that:
- Chrome for Android might not respond to touch events
- Xiaomi HyperOS system UI loses all blur effects
Options
interface ScrcpySetDisplayPowerControlMessage {
on: boolean;
}
on: The screen power mode. UseAndroidScreenPowerMode.Off(0) to turn off the screen, orAndroidScreenPowerMode.Normal(2) to set screen to normal power mode.(until v2.7) Whether to turn the screen on (true) or off (false).(since v3.0)
Changelog
v1.15
modefield acceptsAndroidScreenPowerModeenum with valuesOff(0) andNormal(2).
v3.0
- Breaking:
modefield replaced withonboolean parameter.trueis equivalent toAndroidScreenPowerMode.Normal,falseis equivalent toAndroidScreenPowerMode.Off.
Usage
- JavaScript
- TypeScript
import { AndroidScreenPowerMode } from "@yume-chan/scrcpy";
// Using `ScrcpyControlMessageSerializer`
const message = serializer.setDisplayPower(AndroidScreenPowerMode.Normal);
// Using `ScrcpyControlMessageWriter`
await writer.setDisplayPower(AndroidScreenPowerMode.Normal);
// Using `AdbScrcpyClient`
await client.controller.setDisplayPower(AndroidScreenPowerMode.Normal);
import { AndroidScreenPowerMode } from "@yume-chan/scrcpy";
// Using `ScrcpyControlMessageSerializer`
const message: Uint8Array = serializer.setDisplayPower(AndroidScreenPowerMode.Normal);
// Using `ScrcpyControlMessageWriter`
await writer.setDisplayPower(AndroidScreenPowerMode.Normal);
// Using `AdbScrcpyClient`
await client.controller!.setDisplayPower(AndroidScreenPowerMode.Normal);
info
Since Scrcpy v3.0, the AndroidScreenPowerMode enum is no longer used. Use true for normal mode and false for off mode.
// Since v3.0
await writer.setDisplayPower(true); // Turn screen on
await writer.setDisplayPower(false); // Turn screen off