 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Lexikos
Joined: 17 Oct 2006 Posts: 4469 Location: Qld, Australia
|
Posted: Thu Oct 04, 2007 6:55 am Post subject: |
|
|
| What does EnumDisplayDevices Example 2 output? Do either of the hotkeys do anything? |
|
| Back to top |
|
 |
novis Guest
|
Posted: Thu Oct 04, 2007 3:36 pm Post subject: |
|
|
| im not sure about example2 its in comment and he said i should use the script as is. There's nothing in the "Script lines most recently executed.. window |
|
| Back to top |
|
 |
novis Guest
|
Posted: Thu Oct 04, 2007 3:55 pm Post subject: |
|
|
ive tried use example2 like this... dont know if its right
| Code: |
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#+NumpadMult::EnableDisplayDevice("\\.\DISPLAY1", -1)
#+NumpadDiv::EnableDisplayDevice("\\.\DISPLAY2", -1)
; EnumDisplayDevices(Index [, ByRef Name, ByRef StateFlags ] )
;
; Index: One-based index of device to get info for.
; DeviceName: [out] The name of the device.
; StateFlags: [out] Any reasonable combination of the following flags:
; 0x00000001 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
; 0x00000004 DISPLAY_DEVICE_PRIMARY_DEVICE
; 0x00000008 DISPLAY_DEVICE_MIRRORING_DRIVER
; DeviceKey: [out] Path to the device's registry key relative to HKEY_LOCAL_MACHINE.
;
; Returns true if the display device exists, otherwise false.
;
/* Example 1 (requires EnableDisplayDevice()):
SecondaryDevice =
count = 0
Loop {
if ! EnumDisplayDevices(A_Index, DeviceName, StateFlags)
break
if !(StateFlags & 8) ; not a pseudo-device
if (++count = 2) ; second device
break
}
if DeviceName
EnableDisplayDevice(DeviceName, -1) ; toggle
*/
/* 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
}
; Enables, disables or toggles a display device.
;
; DeviceName: The name of the device, e.g. \\.\DISPLAY1
; Action: The action to take.
; 0 Disable
; 1 Enable
; -1 Toggle (may not be reliable if NoReset=true)
; 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
;
; Examples:
; ; disable display 2
; EnableDisplayDevice("\\.\DISPLAY2", 0)
; Sleep, 10000
;
; ; simultaneously enable display 2 and disable display 1
; EnableDisplayDevice("\\.\DISPLAY2", 1, true)
; EnableDisplayDevice("\\.\DISPLAY1", 0)
; Sleep, 10000
;
; ; ensure both are enabled
; EnableDisplayDevice("\\.\DISPLAY2", 1, true)
; EnableDisplayDevice("\\.\DISPLAY1")
;
; Note: DeviceNames may vary. Rather than hard-coding the device name,
; EnumDisplayDevices() should be used to enumerate the devices.
;
EnableDisplayDevice(DeviceName, Action=1, NoReset=false)
{
if (Action = -1)
{ ; Determine if the display should be enabled or disabled.
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%
}
VarSetCapacity(devmode, 156, 0)
NumPut(156, devmode, 36, "UShort")
; Set DEVMODE.dmFields to indicate which fields are valid.
if (Action) ; Enable
NumPut(0x000020, devmode, 40) ; position={0,0}
else ; Disable
NumPut(0x180020, devmode, 40) ; width=0, height=0, position={0,0}
; Since CDS_NORESET is specified here, if NoReset=true, the user must
; manually call ChangeDisplaySettings(NULL,1) or restart the computer.
err := DllCall("ChangeDisplaySettingsEx", "str", DeviceName
, "uint", &devmode, "uint", 0, "uint", 0x10000001, "uint", 0)
; ChangeDisplaySettings() is called here for two reasons:
; - A restart is otherwise required to enable a secondary display device.
; See: http://support.microsoft.com/kb/308216
; - Disabling display devices with just ChangeDisplaySettingsEx()
; tends to leave them turned on.
if (!err && !NoReset)
err := DllCall("ChangeDisplaySettings", "uint", 0, "uint", 1)
return err
}
|
|
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 4469 Location: Qld, Australia
|
Posted: Thu Oct 04, 2007 4:18 pm Post subject: |
|
|
| novis wrote: | | im not sure about example2 its in comment and he said i should use the script as is. | Sorry, just uncomment it.
Running this as is should output a list of display device names:
| 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
} |
Pressing Ctrl+C at the message box should copy the list to the clipboard. |
|
| Back to top |
|
 |
novis Guest
|
Posted: Thu Oct 04, 2007 5:17 pm Post subject: |
|
|
---------------------------
enableDev.ahk
---------------------------
\\.\DISPLAY1 is the primary display device.
\\.\DISPLAYV1 is a pseudo-device.
---------------------------
OK
--------------------------- |
|
| Back to top |
|
 |
novis Guest
|
Posted: Thu Oct 04, 2007 5:34 pm Post subject: |
|
|
| i wonder if matrox locked it somehow ..for instance i cant change Res from rightclicking on desktop. Only from "Matrox-Powerdesk SE" |
|
| Back to top |
|
 |
novis Guest
|
Posted: Thu Oct 04, 2007 5:57 pm Post subject: |
|
|
ok now ive messed things up :/
in my matrox powerdesk util i changed from:
Use Advanced Matrox Display Controls
to
Use Windows Display Controls
and now .txt files opens minimized ...weird. other shortcuts opens normal.
ive changed it back and it remains like that. hmm |
|
| Back to top |
|
 |
novis Guest
|
Posted: Thu Oct 04, 2007 6:42 pm Post subject: |
|
|
hmm 4th post ..cant edit post?
i had to do a complete removal of matrox driver to get rid of it all. now its all good.
ive tried this (now using Windows Display Control)
still nothing..
| Code: |
#NoEnv
#+NumpadDiv::EnableDisplayDevice("\\.\DISPLAYV1", 1)
EnableDisplayDevice(DeviceName, Action=1, NoReset=false)
{
if (Action = -1)
{
Loop {
if ! EnumDisplayDevices(A_Index, this_name, this_state)
break
if (this_name = DeviceName) {
Action := !(this_state & 1) ; DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
break
}
}
}
VarSetCapacity(devmode, 156, 0)
NumPut(156, devmode, 36, "UShort")
if (Action) ; Enable
NumPut(0x000020, devmode, 40) ; position={0,0}
else ; Disable
NumPut(0x180020, devmode, 40) ; width=0, height=0, position={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
}
;/* 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
}
|
|
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 7698 Location: Germany (but I only speak English)
|
Posted: Thu Oct 04, 2007 11:01 pm Post subject: |
|
|
if you register, you can edit your new posts. _________________
Unless noted, all code is UNTESTED.
Answers Here: 1.(Loops, Viruses, etc.) 2.Search 3.RTFM 4.Ask for Help.
PMs will be ignored unless you are hiring me. |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 4469 Location: Qld, Australia
|
Posted: Fri Oct 05, 2007 1:56 am Post subject: |
|
|
| novis wrote: | ive tried this (now using Windows Display Control)
still nothing..
| Code: | | #+NumpadDiv::EnableDisplayDevice("\\.\DISPLAYV1", 1) |
|
\\.\DISPLAYV1 isn't a "real" display device. Try running the script (example 2) again, assuming you haven't since you uninstalled the Matrox drivers.
| Quote: | \\.\DISPLAY1 is the primary display device.
\\.\DISPLAYV1 is a pseudo-device. |
|
|
| Back to top |
|
 |
novis Guest
|
Posted: Fri Oct 05, 2007 8:45 pm Post subject: |
|
|
ok but then what should i do with the output
| Quote: |
---------------------------
enableDev.ahk
---------------------------
\\.\DISPLAY1 is the primary display device.
\\.\DISPLAYV1 is a pseudo-device.
---------------------------
OK
---------------------------
|
|
|
| Back to top |
|
 |
Superfraggle
Joined: 02 Nov 2004 Posts: 1019 Location: London, UK
|
Posted: Wed Oct 10, 2007 10:40 am Post subject: |
|
|
I also tried this and couldnt get it to work.
I used | Code: | | EnableDisplayDevice("\\.\DISPLAY2", 1) |
where \\.\DISPLAY2 is the name reported by enumdisplay adapters when my second monitor was on. But it did nothing. _________________ Steve F AKA Superfraggle
http://r.yuwie.com/superfraggle |
|
| Back to top |
|
 |
jamn Guest
|
Posted: Mon Mar 10, 2008 11:19 pm Post subject: |
|
|
| lexiKos, I've read through this thread several times now and I'm still very confused on what I need to get this up and running. Could you post a version of the script for us beginners, a version that includes everything in one package -- all needed functions, all hotkey code and so on? |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 4469 Location: Qld, Australia
|
Posted: Tue Mar 11, 2008 8:57 am Post subject: |
|
|
| Superfraggle wrote: | I also tried this and couldnt get it to work.
I used | Code: | | EnableDisplayDevice("\\.\DISPLAY2", 1) |
where \\.\DISPLAY2 is the name reported by enumdisplay adapters when my second monitor was on. But it did nothing.
| If your second monitor was already on, attempting to turn it on should do nothing. Use -1 to toggle or 0 to turn it off. Sorry for not replying sooner; I guess I missed your post.
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.)
Last edited by Lexikos on Thu Mar 13, 2008 7:17 am; edited 1 time in total |
|
| Back to top |
|
 |
jamn Guest
|
|
| 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
|