有没有一种以编程方式在 Windows XP 中更改屏幕分辨率或启用/禁用多个显示器的方法?例如,从一个显示器的 1024x768 更改为两个显示器的 1280x1024?我最感兴趣的是一个可以使用 win32 函数完成此操作的方法,但任何可以绑定到 Windows 快捷方式的东西都可以。
您可以使用EnumDisplayDevices来查看可用的显示器,使用EnumDisplaySettings获取显示器可用分辨率列表。使用ChangeDisplaySettings来设置所需的分辨率。
更改主显示器的显示分辨率:
import win32api
import win32con
import pywintypes
devmode = pywintypes.DEVMODEType()
devmode.PelsWidth = 1920
devmode.PelsHeight = 1080
devmode.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT
win32api.ChangeDisplaySettings(devmode, 0)
如果您需要一个提供不同分辨率选择的Python脚本,请查看https://github.com/randyramsaywack/changeResolution。
你可以使用http://www.autohotkey.com轻松编写脚本
以下是一个脚本,可通过Windows+1和Windows+2在一个显示器和两个显示器之间进行切换
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Recommended for catching common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#1::
Send {LWin}
WinWaitActive Start menu
Send Adjust Screen Resolution
Send {enter}
WinWaitActive Screen Resolution
ControlClick ComboBox3
Send {PgDn}
Send {Up} ; Select "Show desktop only on 1"
Send {enter}
Sleep 3000 ; workaround - cannot select accept/revert window?
Send {left}
Send {enter} ; accept changes
Return
#2::
Send {LWin}
WinWaitActive Start menu
Send Adjust Screen Resolution
Send {enter}
WinWaitActive Screen Resolution
ControlClick ComboBox3
Send {PgDn}
Send {Up}
Send {Up} ; Select "Extend these displays"
Send {enter}
Sleep 3000 ; workaround - cannot select accept/revert window?
Send {left}
Send {enter} ; accept changes
Return