Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Secondary Monitor


  • Please log in to reply
70 replies to this topic
socd
  • Members
  • 6 posts
  • Last active: Aug 14 2010 12:36 PM
  • Joined: 22 Nov 2009
I don't know what it does.
System: Windows 7 64 Bit, 8GB Ram, GTX 260, Raptor Raid

vitalyb
  • Members
  • 18 posts
  • Last active: Nov 23 2010 06:15 AM
  • Joined: 28 Mar 2006
Nice! @ socd.

Here are all the switches, if needed:

Projector only
displayswitch /external

Monitor only
displayswitch /internal

Project and monitor both
displayswitch /extend

Monitor cloned
displayswitch /clone
Vitaly

socd
  • Members
  • 6 posts
  • Last active: Aug 14 2010 12:36 PM
  • Joined: 22 Nov 2009
Thanks.
System: Windows 7 64 Bit, 8GB Ram, GTX 260, Raptor Raid

nathang
  • Members
  • 2 posts
  • Last active: Mar 10 2010 12:38 AM
  • Joined: 10 Mar 2010
When I plug in my external monitor, it automatically takes the "\\.\DISPLAY1" name away from my laptop. and sets the display to clone.

I want to be able to make my laptop (now calling itself "\\.\DISPLAY1") the primary display and extend to my external monitor ("\\.\DISPLAY1")

Can anyone help me achieve this?

Gauss
  • Members
  • 203 posts
  • Last active: Jan 27 2012 12:49 PM
  • Joined: 10 Sep 2009
I think you can do that in your video card control panel

nathang
  • Members
  • 2 posts
  • Last active: Mar 10 2010 12:38 AM
  • Joined: 10 Mar 2010

I think you can do that in your video card control panel


yes I can, but I have to do it every time I plug my monitor in, and I wanted AHK to speed up the task

  • Guests
  • Last active:
  • Joined: --

Is it possible to enable/disable a secondary monitor using a hotkey?
If so can someone please explain.



Gauss
  • Members
  • 203 posts
  • Last active: Jan 27 2012 12:49 PM
  • Joined: 10 Sep 2009
DisplaySwitch()

DisplaySwitch(){

	Gui +LastFound +AlwaysOnTop -Caption +ToolWindow

	Gui, Color, White

	Gui, Font, s350, Ariel

	WinSet, TransColor, White 220

	SysGet, MonitorCount, MonitorCount

	Display := (MonitorCount = 2) ? "PC" : "TV", Switch := (MonitorCount = 2) ? "/internal" : "/extend"

	RunWait, displayswitch %Switch%

	Gui, Add, Text, x0 y0 w800 h600 center cGreen, %Display%

	Gui, Show, w800 h600 NoActivate

	Sleep, 1500

	Gui, Destroy

    }


ikarus
  • Guests
  • Last active:
  • Joined: --
Hello,

I have a notebook, and when it is attached to the docking station at the office, I use a second monitor. Now I tried all the scripts in this thread, but none of them switch this secondary monitor on or off.

Using the very first script from this thread I get the message: "Error getting display attached status."

Using this one:
; EnumDisplayDevices(Index [, ByRef Name, ByRef StateFlags ] )
;
; ... removed "documentation"
;
;/* Example 2:
    Loop {
        if ! EnumDisplayDevices(A_Index, DeviceName, StateFlags)
            break
        if (StateFlags & 4)
            text .= DeviceName " is the primary display device.`n"
        else if (StateFlags & 1)
            text .= "The desktop extends onto " DeviceName ".`n"
        if (StateFlags & 8)
            text .= DeviceName " is a pseudo-device.`n"
    }
    MsgBox %text%
;*/
EnumDisplayDevices(Index, ByRef DeviceName, ByRef StateFlags="", ByRef DeviceKey="")
{
    ; DISPLAY_DEVICE DisplayDevice
    VarSetCapacity(DisplayDevice, 424)
    ; lpDisplayDevice.cb := sizeof(DISPLAY_DEVICE)
    NumPut(424, DisplayDevice, 0)
   
    VarSetCapacity(DeviceName, 32, 0)
    VarSetCapacity(DeviceKey, 128, 0)
    ; For consistency, clear StateFlags in case of failure.
    StateFlags = 0
   
    if ! DllCall("EnumDisplayDevices"
        , "UInt", 0
        , "UInt", Index-1
        , "UInt", &DisplayDevice
        , "UInt", 0)
        return false
   
    StateFlags := NumGet(DisplayDevice, 164)
    DllCall("lstrcpynA", "Str", DeviceName, "UInt", &DisplayDevice+4,   "int", 32)
    DllCall("lstrcpynA", "Str", DeviceKey,  "UInt", &DisplayDevice+296, "int", 128)
    if (SubStr(DeviceKey,1,18)="\Registry\Machine\")
        DeviceKey := SubStr(DeviceKey,19)
    return true
}
I get a message box containing only the OK button.

Is there any possible solution to my problem out there?

Thanks,
ikarus

Desi
  • Members
  • 162 posts
  • Last active: Apr 15 2015 09:51 AM
  • Joined: 29 Oct 2010
The Windows+P shortcut (on Win 7 at least) can be used to enable, disable, or set multiple monitors and projectors.

Guest1
  • Guests
  • Last active:
  • Joined: --

Here is an updated EnableDisplayDevice:

; Enables, disables or toggles a display device.
;
; DeviceName:   The name of the device, e.g. \\.\DISPLAY1
;               Alternatively, it can be the index of the device, which might
;               not be the same as the number shown in Display Settings.
; Action:       The action to take.
;                    0   Disable (false is synonymous with 0)
;                    1   Enable (true is synonymous with 1)
;                   -1   Toggle
; NoReset:      If true, settings will be saved to the registry, but not applied.
;
; The following can be used to apply settings saved in the registry:
;   DllCall("ChangeDisplaySettings", "uint", 0, "uint", 1)
;
; Return values:
;    DISP_CHANGE_SUCCESSFUL       0
;    DISP_CHANGE_RESTART          1
;    DISP_CHANGE_FAILED          -1
;    DISP_CHANGE_BADMODE         -2
;    DISP_CHANGE_NOTUPDATED      -3
;    DISP_CHANGE_BADFLAGS        -4
;    DISP_CHANGE_BADPARAM        -5
;
EnableDisplayDevice(DeviceName, Action=1, NoReset=false)
{
    if (Action = -1) || (DeviceName+0 != "")
    {
        VarSetCapacity(DisplayDevice, 424), NumPut(424, DisplayDevice, 0)
        VarSetCapacity(ThisDeviceName, 32, 0)
        Index = 0
        Loop {
            if !DllCall("EnumDisplayDevices", "UInt", 0, "UInt", A_Index-1, "UInt", &DisplayDevice, "UInt", 0)
                return -5
            ThisDeviceState := NumGet(DisplayDevice, 164)
            Index += 1
            DllCall("lstrcpynA", "Str", ThisDeviceName, "UInt", &DisplayDevice+4, "int", 32)
            if (DeviceName = Index || DeviceName = ThisDeviceName)
            {
                if Action = -1
                    Action := !(ThisDeviceState & 1)
                DeviceName := ThisDeviceName
                break
            }
        }
    }
    VarSetCapacity(devmode, 156, 0), NumPut(156, devmode, 36, "UShort")
    if Action
        NumPut(0x000020, devmode, 40) ; Enable by setting position = {0,0}
    else
        NumPut(0x180020, devmode, 40) ; Disable by setting size = {0,0}
    err := DllCall("ChangeDisplaySettingsEx", "str", DeviceName, "uint", &devmode, "uint", 0, "uint", 0x10000001, "uint", 0)
    if !err && !NoReset
        err := DllCall("ChangeDisplaySettings", "uint", 0, "uint", 1)
    return err, ErrorLevel:=Action
}
It can be used as follows:
; disable display 2
EnableDisplayDevice(2, false)
Sleep, 10000

; simultaneously enable display 2 and disable display 1
EnableDisplayDevice(2, true, true)
EnableDisplayDevice(1, false)
Sleep, 10000

; ensure both are enabled
EnableDisplayDevice(2, true, true)
EnableDisplayDevice(1)
(Edit: corrected comment about device numbering and display settings.)

Lexikos' code still works well... under AHK-Basic. Could anybody adopt it to AHK_L? I don't have any knowledge on DllCall, NumPut and VarSetCapacity.
Thanks in advance.