 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
socd
Joined: 22 Nov 2009 Posts: 6
|
Posted: Wed Dec 02, 2009 12:03 am Post subject: |
|
|
I don't know what it does. _________________ System: Windows 7 64 Bit, 8GB Ram, GTX 260, Raptor Raid |
|
| Back to top |
|
 |
vitalyb
Joined: 28 Mar 2006 Posts: 17
|
Posted: Fri Jan 15, 2010 5:42 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
socd
Joined: 22 Nov 2009 Posts: 6
|
Posted: Sat Jan 16, 2010 2:44 am Post subject: |
|
|
Thanks. _________________ System: Windows 7 64 Bit, 8GB Ram, GTX 260, Raptor Raid |
|
| Back to top |
|
 |
nathang
Joined: 10 Mar 2010 Posts: 2
|
Posted: Wed Mar 10, 2010 12:39 am Post subject: |
|
|
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? |
|
| Back to top |
|
 |
Gauss
Joined: 10 Sep 2009 Posts: 203
|
Posted: Wed Mar 10, 2010 8:54 am Post subject: |
|
|
| I think you can do that in your video card control panel |
|
| Back to top |
|
 |
nathang
Joined: 10 Mar 2010 Posts: 2
|
Posted: Wed Mar 10, 2010 9:24 am Post subject: |
|
|
| Gauss wrote: | | 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 |
|
| Back to top |
|
 |
Guest
|
Posted: Fri May 07, 2010 8:59 pm Post subject: Re: Secondary Monitor |
|
|
| Goodfare wrote: | Is it possible to enable/disable a secondary monitor using a hotkey?
If so can someone please explain. |
|
|
| Back to top |
|
 |
Gauss
Joined: 10 Sep 2009 Posts: 203
|
Posted: Fri Aug 13, 2010 10:36 am Post subject: |
|
|
| Code: | 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
} |
|
|
| Back to top |
|
 |
ikarus Guest
|
Posted: Tue Feb 08, 2011 12:43 pm Post subject: |
|
|
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: | Code: | ; 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 |
|
| Back to top |
|
 |
Desi
Joined: 29 Oct 2010 Posts: 142 Location: Sydney, Australia
|
Posted: Tue Feb 08, 2011 9:18 pm Post subject: |
|
|
| The Windows+P shortcut (on Win 7 at least) can be used to enable, disable, or set multiple monitors and projectors. |
|
| Back to top |
|
 |
Guest1 Guest
|
Posted: Thu Dec 29, 2011 12:00 pm Post subject: |
|
|
| Lexikos wrote: | Here is an updated EnableDisplayDevice:
| Code: | ; 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: | Code: | ; 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. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|