Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- VK91::SetRefreshrateMainMonitor(120) ; SL
- +VK91::SetRefreshrateMainMonitor(165) ; shift+SL
- #VK91::CheckMonitors() ; win+SL
- SetRefreshrateMainMonitor(Refreshrate) {
- SysGet, Monitor, MonitorPrimary
- ; Monitor := 2
- Refreshrate := Refreshrate
- SysGet, MonitorCount, MonitorCount
- If (Monitor > MonitorCount OR Monitor == 0 OR Monitor < -1) {
- TrayTip, AHK Monitor Change, Failed: Monitor Count incorrect, 5
- }
- EnumDisplayDevices(Monitor, DeviceName, StateFlags)
- ChangeRefreshrate(DeviceName, Refreshrate)
- return
- }
- CheckMonitors() {
- text := ""
- TotalPixels := ""
- PixelsPerSecond := ""
- Loop {
- if ! EnumDisplayDevices(A_Index, DeviceName, StateFlags)
- break
- if (StateFlags & 4) { ; text .= "Primary display device is " DeviceName "`n"
- ReadMonitor(DeviceName, Msg, Pixels, Pps)
- TotalPixels += Pixels
- PixelsPerSecond += Pps
- text .= "Monitor " A_Index " " Msg "`n"
- }
- else if (StateFlags & 1){ ; text .= "The desktop extends onto " DeviceName "`n"
- ReadMonitor(DeviceName, Msg, Pixels, Pps)
- TotalPixels += Pixels
- PixelsPerSecond += Pps
- text .= "Monitor " A_Index " " Msg "`n"
- }
- else if (StateFlags & 8){ ; text .= DeviceName " is a pseudo-device`n"
- }
- else{ ; text .= DeviceName " is disabled`n"
- }
- }
- TotalPixels := ThousandsSep(TotalPixels)
- PixelsPerSecond := ThousandsSep(PixelsPerSecond)
- MsgBox, 0, AHK Read Monitor Settings, %text% `n`n Total Pixels %TotalPixels% `n Pixels per Second %PixelsPerSecond%
- return
- }
- ThousandsSep(x, s=".") {
- return RegExReplace(x, "\G\d+?(?=(\d{3})+(?:\D|$))", "$0" s)
- }
- ChangeRefreshrate(MonitorName, refreshRate) {
- VarSetCapacity(dM,156,0),
- NumPut(156,2,&dM,36)
- DllCall( "EnumDisplaySettingsA", Str, MonitorName, UInt, -1, UInt, &dM),
- NumPut(0x5c0000,dM,40)
- NumPut(refreshRate,dM,120)
- ; Return DllCall( "ChangeDisplaySettingsA", UInt,&dM, UInt,0 )
- Return DllCall( "ChangeDisplaySettingsExA", Str, MonitorName, UInt,&dM, UInt,0, UInt,0 )
- }
- ReadMonitor(MonitorName, ByRef Msg, ByRef Pixels, ByRef Pps) {
- Msg := ""
- Pixels := 0
- Pps := 0
- VarSetCapacity(dM,156,0),
- NumPut(156,2,&dM,36)
- DllCall( "EnumDisplaySettingsA", Str, MonitorName, UInt, -1, UInt, &dM),
- Out_1:=NumGet(&dM,108,"uint4") ; ScreeWidth
- Out_2:=NumGet(&dM,112,"uint4") ; ScreenHeight
- ; Out_3:=NumGet(&dM,104,"uint4") ; ColorDepth
- Out_4:=NumGet(&dM,120,"uint4") ; Frequency
- ; TrayTip, AHK Read Monitor Settings, %Out_1%x%Out_2% @ %Out_3%bit %Out_4%Hz, 5
- ; Msg := Out_1 "x" Out_2 " @ " Out_3 "bit " Out_4 "Hz"
- Msg := Out_1 "x" Out_2 " @ " Out_4 " Hz"
- Pixels := Out_1 * Out_2
- Pps := Pixels * Out_4
- Return
- }
- EnumDisplayDevices(Index, ByRef DeviceName, ByRef StateFlags:="", ByRef DeviceKey:="") {
- VarSetCapacity(DisplayDevice, 424)
- NumPut(424, DisplayDevice, 0)
- StateFlags := 0 ; For consistency, clear StateFlags in case of failure.
- DeviceName := ""
- DeviceKey := ""
- if ! DllCall("EnumDisplayDevicesA"
- , "ptr", 0
- , "uint", Index-1
- , "ptr", &DisplayDevice
- , "uint", 0)
- return false
- StateFlags := NumGet(DisplayDevice, 164)
- ; DeviceName := StrGet(&DisplayDevice+4, 32, "cp0")
- DeviceName := StrGet(&DisplayDevice+4, 32)
- DeviceKey := StrGet(&DisplayDevice+296, 128, "cp0")
- if (SubStr(DeviceKey,1,18)="\Registry\Machine\")
- DeviceKey := SubStr(DeviceKey,19)
- return true
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement