AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Vista Media Center Multitool
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Blahman



Joined: 09 Nov 2008
Posts: 25

PostPosted: Mon Nov 10, 2008 2:59 am    Post subject: Vista Media Center Multitool Reply with quote

This is my first released AHK script. It's just something I put together for my own use and thought others out there might find it helpful, or as a starting place to make their own. Right now it's just a script, no GUI, and is only meant for use with one or two monitors. It was developed on a 16:9 monitor and I'm not sure how it will handle on monitors with other aspect ratios, but if you find anything wonky please let me know.

Background:
I wanted to use Vista's Windows Media Center to watch TV while I'm doing other things with my computer including playing full-screen games. I have a 37" 1080p HDTV that has multiple inputs which I've hooked up so I can essentially use its PIP function as a second monitor. Windows Media Center has a very slick interface but there are some huge holes in its usability from a practical standpoint. It does not play nicely in full-screen mode, locking your mouse to its window if you have multiple monitors for example, and there's a lengthy delay whenever you try to Alt-Tab to escape its grasp. Also, Windows in general won't let you view two full-screen applications at the same time even if you have multiple monitors. One has to be windowed, and since games tend to run better when they're full-screen, that's another reason to run Media Center in a window. But how to make it at least look like it's full-screen on the second monitor? Well it's possible with AHK to remove the window borders and titlebar, as well as set its size and position.

I also wanted to be able to mute only Media Center, leaving my other programs and games unmuted. This is also possible in Vista, using the Volume Mixer and AHK to control it.

Finally there were a few issues with running Media Center in a window that I had to work around in order to have as seamless an experience as possible. First of all what happens to the window on the secondary monitor when the resolution on the primary monitor changes (e.g. when launching a full-screen game that is set at a lower resolution for performance reasons)? It shifts, rather annoyingly, and gets split between the two monitors. The other problem was how the cursor never goes away when it's hovering over a Media Center window. The normal behavior in full-screen is that the cursor disappears after ~5 seconds. Well I was able to work around both of these issues, at least to the best of my limited AHK scripting abilities.

Features:
- Virtual full-screen modes provide seamless mouse movement across screens and allows full-screen Media Center usage on second monitor while playing full-screen games on primary monitor
- Causes the Mute button to only affect Windows Media Center as long as it's running. Works without stealing focus from active application/game window, using a minimized Volume Mixer window. Automatically launches and closes the Volume Mixer when Media Center is launched/closed.
- Uses a context-specific hotkey (default: Shift-3) to cycle between 3 different windowed modes, 4 if you have a secondary monitor:
    - Virtual full-screen on primary monitor (full-size window without borders)
    - Small window in the bottom-right corner (windowed with borders)
    - Small window in the bottom-right corner (windowed without borders)
    - Virtual full-screen on secondary monitor (full-size window without borders)
- Listens for resolution changes on the primary monitor and automatically adjusts the positioning of the Media Center window to fit properly when using the virtual full-screen mode on secondary monitor.
- Hides the cursor when it hovers over the Media Center window for 5 seconds.

To do/wishlist:
- Create a GUI for customization and ease of use
- More/different windowing modes/placements
- Ability to intercept remote control keys and pass them to Media Center without stealing focus from active window.
- Ability to adjust mixer volumes and muting with hotkeys (master, active window, and Media Center)
- Compatibility with 3+ monitors

If anyone has any ideas or code samples on how to do any of the above, I would really be interested!

And if you have feedback/questions/problems regarding this script just post, PM or email!

Finally of course, here is the code so far. Feel free to customize it or use it any way you wish. I only ask that you please post your improvements/tweaks to the code here for all to see and use.

Code:

/*
Vista Media Center Multitool
Created by Blahman (blah238 at gmail dot com)
v0.1
11/9/2008

Features:
- Virtual full-screen modes provide seamless mouse movement across screens and allows full-screen Media Center usage on second monitor while playing full-screen games on primary monitor
- Causes the Mute button to only affect Windows Media Center as long as it's running. Works without stealing focus from active application/game window, using a minimized Volume Mixer window. Automatically launches and closes the Volume Mixer when Media Center is launched/closed.
- Uses a context-specific hotkey (default: Shift-3) to cycle between 3 different windowed modes, 4 if you have a secondary monitor:
   - Virtual full-screen on primary monitor (full-size window without borders)
   - Small window in the bottom-right corner (windowed with borders)
   - Small window in the bottom-right corner (windowed without borders)
   - Virtual full-screen on secondary monitor (full-size window without borders)
- Listens for resolution changes on the primary monitor and automatically adjusts the positioning of the Media Center window to fit properly when using the virtual full-screen mode on secondary monitor.
- Hides the cursor when it hovers over the Media Center window for 5 seconds.

Feel free to customize this code or use it any way you wish. I only ask that you please post your improvements/tweaks to the code on the AHK forums for all to see and use.
*/

#SingleInstance, Force
SetDefaultMouseSpeed, 0
CoordMode, Mouse, Screen
cycle = 1 ; counter to keep track of the windowing mode to use next in a cycle

WaitForWMC:
Process, Wait, ehshell.exe ; Waits for Windows Media Center to be run
WMCPID = %ErrorLevel%
Process, Exist, SndVol.exe ; Vista's Volume Mixer is used to mute Media Center independently from other apps
SndVolPID = %ErrorLevel%
If SndVolPID = 0
   Run, SndVol.exe, , Min, SndVolPID
ScrW := A_ScreenWidth
ScrH := A_ScreenHeight
SetTimer, CheckForResChange, On ; Sets a Timer that listens for primary monitor resolution changes
Gosub, MouseHideOn ; Sets a Timer that hides the cursor if it hovers over Media Center's window
; All timers use the default 250ms resolution -- feel free to speed them up if desired

; Cleans up whenever Media Center is closed
Process, WaitClose, %WMCPID%
WinClose, ahk_pid %SndVolPID%
SetTimer, CheckForResChange, Off
Gosub, MouseHideOff
Goto WaitForWMC
return

; Adjusts window when primary monitor resolution changes, e.g. when launching a full-screen game that uses a different resolution than the desktop
CheckForResChange:
if (A_ScreenWidth <> ScrW or A_ScreenHeight <> ScrH)
{
   SysGet, monitorcount, MonitorCount
   if (monitorcount = 1 or cycle <> 5) ; Only interested when using virtual full-screen on second monitor
      return
   sleep, 2500 ; sometimes resolution changes take a while...
   SysGet, Mon2, Monitor, 2
   Mon2W := Mon2Right - Mon2Left
   Mon2H := Mon2Bottom - Mon2Top
   WinGetPos, WMCx, WMCy,,, ahk_pid %WMCPID%
   if (WMCx <> Mon2Left or WMCy <> Mon2Top)
      WinMove, ahk_pid %WMCPID%,, Mon2Left, Mon2Top, Mon2W, Mon2H
   ScrW := A_ScreenWidth
   ScrH := A_ScreenHeight
}
return

#IfWinActive, ahk_class eHome Render Window ; This is the classname of the Windows Media Center application
+3::

; "Restores" the window if it is in true full-screen mode
WinGet, winstyle, Style, ahk_pid %WMCPID%
if (winstyle = 0x16000000) or (winstyle & 0x20000000)
{
   PostMessage, 0x112, 0xF120,,, ahk_pid %WMCPID%
   sleep, 1500
}

SysGet, monitorcount, MonitorCount
SysGet, Wk1, MonitorWorkArea, 1 ; used to avoid placing the window on top of the taskbar
If monitorcount = 2 ; provides 4 different windowing modes, the last places it on the second monitor in virtual full-screen
{
   SysGet, Mon2, Monitor, 2
   Mon2W := Mon2Right - Mon2Left
   Mon2H := Mon2Bottom - Mon2Top
   if cycle in 1,5 ; virtual full-screen on primary monitor
   {
      WinSet, Style, -0xC40000, ahk_pid %WMCPID%
      WinMove, ahk_pid %WMCPID%, , 0, 0, A_ScreenWidth, A_ScreenHeight
      WinActivate, ahk_pid %WMCPID%
      cycle = 2
      return
   }
   if cycle = 2 ; small window with borders, bottom-right of primary monitor
   {
      WinSet, Style, +0xC40000, ahk_pid %WMCPID%
      WinMove, ahk_pid %WMCPID%, , A_ScreenWidth - (A_ScreenWidth - Wk1Right) - 831, A_ScreenHeight - (A_ScreenHeight - Wk1Bottom) - 495, 831, 495
      cycle = 3
      return
   }
   if cycle = 3 ; small window without borders, bottom-right of primary monitor
   {
      WinSet, Style, -0xC40000, ahk_pid %WMCPID%
      WinMove, ahk_pid %WMCPID%, , A_ScreenWidth - (A_ScreenWidth - Wk1Right) - 831, A_ScreenHeight - (A_ScreenHeight - Wk1Bottom) - 467, 831, 467
      cycle = 4
      return
   }
   if cycle = 4 ; virtual full-screen on secondary monitor
   {
      WinSet, Style, -0xC40000, ahk_pid %WMCPID%
      WinMove, ahk_pid %WMCPID%, , Mon2Left, Mon2Top, Mon2W, Mon2H
      cycle = 5
      return
   }

}
Else ; only provides modes for the primary monitor
{
   if cycle in 1,4,5
   {
      WinSet, Style, -0xC40000, ahk_pid %WMCPID%
      WinMove, ahk_pid %WMCPID%, , 0, 0, A_ScreenWidth, A_ScreenHeight
      WinActivate, ahk_pid %WMCPID%
      cycle = 2
      return
   }
   if cycle = 2
   {
      WinSet, Style, +0xC40000, ahk_pid %WMCPID%
      WinMove, ahk_pid %WMCPID%, , A_ScreenWidth - (A_ScreenWidth - Wk1Right) - 831, A_ScreenHeight - (A_ScreenHeight - Wk1Bottom) - 495, 831, 495
      cycle = 3
      return
   }
   if cycle = 3
   {
      WinSet, Style, -0xC40000, ahk_pid %WMCPID%
      WinMove, ahk_pid %WMCPID%, , A_ScreenWidth - (A_ScreenWidth - Wk1Right) - 831, A_ScreenHeight - (A_ScreenHeight - Wk1Bottom) - 467, 831, 467
      cycle = 4
      return
   }
}
return

; Mutes Windows Media Center independently using Vista's Volume Mixer
#IfWinExist, ahk_class eHome Render Window
sc120:: ; scancode for the Mute key
Process, Exist, SndVol.exe
SndVolPID = %ErrorLevel%
If SndVolPID = 0
   {
      Run, SndVol.exe, , Min, SndVolPID
      Sleep, 120
   }
ControlSend, Mute for Windows Media Center, {Space}, ahk_pid %SndVolPID% ; Toggles the mute control for Media Center
return

/*
The following subroutines hide the cursor (placing it in the bottom left corner of the primary monitor)
when it idles over the Media Center window for ~5 seconds, and then returns it to the previous coordinates when the
user begins to move the mouse again.
*/
MouseHideOn:
SetTimer, WaitForMouseIdle, On
return

MouseHideOff:
SetTimer, WaitForMouseIdle, Off
SetTimer, WaitForMouseMove, Off
DllCall("SetCursorPos", int, PosX1, int, PosY1) ; A DllCall is more reliable than MouseMove in multi-monitor setups
return

WaitForMouseIdle:
if A_TimeIdle > 5000
{
   MouseGetPos, PosX1, PosY1
   WinGetPos, WMCx, WMCy, WMCw, WMCh, ahk_pid %WMCPID%
   if ((PosX1 > WMCx and PosX1 < WMCx + WMCw) and (PosY1 > WMCy and PosY1 < WMCy + WMCh)) ; Checks if cursor is positioned over the window
   {
      DllCall("SetCursorPos", int, 0, int, A_ScreenHeight) ; Places cursor in bottom-left corner of primary monitor
      MouseGetPos, PosX2, PosY2
      SetTimer, WaitForMouseIdle, Off
      SetTimer, WaitForMouseMove, On
   }
}
return

WaitForMouseMove:
MouseGetPos, PosX3, PosY3
if (PosX3 <> PosX2 or PosY3 <> PosY2)
{
   DllCall("SetCursorPos", int, PosX1, int, PosY1) ; Returns cursor to its previous position
   SetTimer, WaitForMouseMove, Off
   SetTimer, WaitForMouseIdle, On
}
return


Last edited by Blahman on Thu Nov 13, 2008 6:39 am; edited 2 times in total
Back to top
View user's profile Send private message
PeterPE
Guest





PostPosted: Thu Nov 13, 2008 3:33 am    Post subject: Reply with quote

Thanks.

One question. It would be great if the mute button would only work if Media Center is active. If not active the mute button should work as usual.

Peter
Back to top
PeterPE
Guest





PostPosted: Thu Nov 13, 2008 3:44 am    Post subject: Reply with quote

Thanks.

One question. It would be great if the mute button would only work if Media Center is active. If not active the mute button should work as usual.

Something like
; Mutes Windows Media Center independently using Vista's Volume Mixer
#IfWinExist, ahk_class eHome Render Window
sc120:: ; scancode for the Mute key
IfWinActive, ahk_class eHome Render Window
{
Process, Exist, SndVol.exe
SndVolPID = %ErrorLevel%
If SndVolPID = 0
{
Run, SndVol.exe, , Min, SndVolPID
Sleep, 120
}
ControlSend, Mute for Windows Media Center, {Space}, ahk_pid %SndVolPID% ; Toggles the mute control for Media Center
}
return



Peter
Back to top
Blahman



Joined: 09 Nov 2008
Posts: 25

PostPosted: Thu Nov 13, 2008 4:27 am    Post subject: Reply with quote

Yeah that's more of a user preference. I definitely prefer being able to mute it regardless of whether it's the active window. That'd definitely be an option's I'd put in the GUI/config though.

I'm glad someone out there is taking an interest in it!

And actually you can just change the line
Code:
#IfWinExist, ahk_class eHome Render Window


to
Code:
#IfWinActive, ahk_class eHome Render Window

to achieve that effect.
Back to top
View user's profile Send private message
PeterPE
Guest





PostPosted: Thu Nov 13, 2008 5:52 am    Post subject: Reply with quote

Thanks for the hint. I am still learning AHK.

One more question. Is it possible to run SndVol "hidden"?

Peter
Back to top
Blahman



Joined: 09 Nov 2008
Posts: 25

PostPosted: Thu Nov 13, 2008 6:12 am    Post subject: Reply with quote

If you run it with the "Hide" option instead of "Min", the ControlSend command doesn't work. Regardless of DetectHiddenWindows. So no, unless I am missing something else.
Back to top
View user's profile Send private message
PeterPE
Guest





PostPosted: Thu Nov 13, 2008 6:45 am    Post subject: Reply with quote

Well, I understand.

I guess Chris should update The SoundSet function to reflect the changes in Vista Smile

Peter
Back to top
Blahman



Joined: 09 Nov 2008
Posts: 25

PostPosted: Thu Nov 13, 2008 6:49 am    Post subject: Reply with quote

That would be cool with me Smile
Back to top
View user's profile Send private message
bidomo



Joined: 05 Feb 2009
Posts: 59

PostPosted: Sun Jun 07, 2009 2:55 am    Post subject: Reply with quote

Looks very useful to me!!!

I'm actually using something called The Maxifier to get virtual full screen, and I'm gonna try your script, and keep it as I'm getting very attached to Ahk.


Thanks!


BTW, ControlSend seems to be very useful to get the remote to send commands to VMC even if it doesn't have the focus (IfWinexist instead of IfwinActive, if media center window or process doesn't exist, you can still send the normal remote commands).
Back to top
View user's profile Send private message
Blahman



Joined: 09 Nov 2008
Posts: 25

PostPosted: Sun Jun 07, 2009 3:35 am    Post subject: Reply with quote

Hey there, thanks for checking it out. I actually used The Maxifier at first as well which is what gave me the idea but it had some problems, the biggest being that it caused crashes.

Anyways I've found that this doesn't work so well in Windows 7. Apparently some of the SysGet stuff this script does is broken in Win7 as well as ControlSend not working on minimized windows.

On the upside, full-screen Windows 7 Media Center on one monitor works alongside full-screen games on the other, out of the box.
Back to top
View user's profile Send private message
bidomo



Joined: 05 Feb 2009
Posts: 59

PostPosted: Sun Jun 07, 2009 8:49 am    Post subject: Reply with quote

That's great!!

I'm thinking about checking win 7, but I would really like to add more RAM before that, and is good to know that problem has been solved.


I know this isn't a chat, but, which version are you trying? I would like to check x64, as I'm using vista x64 and I like it much more than XP x64
Back to top
View user's profile Send private message
samhnky



Joined: 29 Sep 2009
Posts: 75

PostPosted: Sun Oct 18, 2009 4:46 am    Post subject: Perfect!!! Reply with quote

For 1.5 years now one of my biggest complaints about my Vista machine was the way the full screen mode on the Media center was so poorly implemented for a dual screen system... This AHK script has now completely fixed that problem. I would like to put on the board though for other noobies, and or users trying it out for the first time after midnight that the command for changing the modes:

Change Display modes: "Shift"+"3"
Back to top
View user's profile Send private message
Blahman



Joined: 09 Nov 2008
Posts: 25

PostPosted: Sun Oct 18, 2009 4:50 am    Post subject: Reply with quote

Glad you like it!

You can easily change the hotkey if you'd like. I just used that because that was the last free button on my remote Smile

Look for the line "+3::"

and change it to your liking. Read the AHK help for hotkey syntax.
Back to top
View user's profile Send private message
Blahman



Joined: 09 Nov 2008
Posts: 25

PostPosted: Sun Oct 18, 2009 5:05 am    Post subject: Reply with quote

By the way, here's a version for Windows 7. There are a couple slight quirks compared to the Vista version in that the Volume Mixer window cannot be minimized, and the borderless window mode doesn't align with the task bar correctly (overlaps it a little).

Code:
/*
Windows 7 Media Center Multitool
Created by Blahman (blah238 at gmail dot com)
v0.2
10/17/2009

Features:
- Virtual full-screen modes provide seamless mouse movement across screens and allows full-screen Media Center usage on second monitor while playing full-screen games on primary monitor
- Causes the Mute button to only affect Windows Media Center as long as it's running. Works without stealing focus from active application/game window, using the Volume Mixer window. Automatically launches and closes the Volume Mixer when Media Center is launched/closed.
- Uses a context-specific hotkey (default: Shift-3) to cycle between 3 different windowed modes, 4 if you have a secondary monitor:
   - Virtual full-screen on primary monitor (full-size window without borders)
   - Small window in the bottom-right corner (windowed with borders)
   - Small window in the bottom-right corner (windowed without borders)
   - Virtual full-screen on secondary monitor (full-size window without borders)
- Listens for resolution changes on the primary monitor and automatically adjusts the positioning of the Media Center window to fit properly when using the virtual full-screen mode on secondary monitor.
- Hides the cursor when it hovers over the Media Center window for 5 seconds.

Feel free to customize this code or use it any way you wish. I only ask that you please post your improvements/tweaks to the code on the AHK forums for all to see and use.
*/

#SingleInstance, Force
;SetTitleMatchMode, 3
;SetTitleMatchMode, slow
SetDefaultMouseSpeed, 0
CoordMode, Mouse, Screen
cycle = 1 ; counter to keep track of the windowing mode to use next in a cycle

WaitForWMC:
Process, Wait, ehshell.exe ; Waits for Windows Media Center to be run
WMCPID = %ErrorLevel%
Process, Exist, SndVol.exe ; Windows' Volume Mixer is used to mute Media Center independently from other apps
SndVolPID = %ErrorLevel%
If SndVolPID = 0
   Run, SndVol.exe, , , SndVolPID
ScrW := A_ScreenWidth
ScrH := A_ScreenHeight
SetTimer, CheckForResChange, On ; Sets a Timer that listens for primary monitor resolution changes
Gosub, MouseHideOn ; Sets a Timer that hides the cursor if it hovers over Media Center's window
; All timers use the default 250ms resolution -- feel free to speed them up if desired

; Cleans up whenever Media Center is closed
Process, WaitClose, %WMCPID%
WinClose, ahk_pid %SndVolPID%
SetTimer, CheckForResChange, Off
Gosub, MouseHideOff
Goto WaitForWMC
return

; Adjusts window when primary monitor resolution changes, e.g. when launching a full-screen game that uses a different resolution than the desktop
CheckForResChange:
if (A_ScreenWidth <> ScrW or A_ScreenHeight <> ScrH)
{
   SysGet, monitorcount, MonitorCount
   if (monitorcount = 1 or cycle <> 5) ; Only interested when using virtual full-screen on second monitor
      return
   sleep, 2500 ; sometimes resolution changes take a while...
   SysGet, Mon2, Monitor, 2
   Mon2W := Mon2Right - Mon2Left
   Mon2H := Mon2Bottom - Mon2Top
   WinGetPos, WMCx, WMCy,,, ahk_pid %WMCPID%
   if (WMCx <> Mon2Left or WMCy <> Mon2Top)
      WinMove, ahk_pid %WMCPID%,, Mon2Left, Mon2Top, Mon2W, Mon2H
   ScrW := A_ScreenWidth
   ScrH := A_ScreenHeight
}
return

#IfWinActive, ahk_class eHome Render Window ; This is the classname of the Windows Media Center application
+3::

; "Restores" the window if it is in true full-screen mode
WinGet, winstyle, Style, ahk_pid %WMCPID%
if (winstyle = 0x16000000) or (winstyle & 0x20000000)
{
   PostMessage, 0x112, 0xF120,,, ahk_pid %WMCPID%
   sleep, 1500
}

SysGet, monitorcount, MonitorCount
SysGet, Wk1, MonitorWorkArea, 1 ; used to avoid placing the window on top of the taskbar
If monitorcount = 2 ; provides 4 different windowing modes, the last places it on the second monitor in virtual full-screen
{
   SysGet, Mon2, Monitor, 2
   Mon2W := Mon2Right - Mon2Left
   Mon2H := Mon2Bottom - Mon2Top
   if cycle in 1,5 ; virtual full-screen on primary monitor
   {
      WinSet, Style, -0xC40000, ahk_pid %WMCPID%
      WinMove, ahk_pid %WMCPID%, , 0, 0, A_ScreenWidth, A_ScreenHeight
      WinActivate, ahk_pid %WMCPID%
      cycle = 2
      return
   }
   if cycle = 2 ; small window with borders, bottom-right of primary monitor
   {
      WinSet, Style, +0xC40000, ahk_pid %WMCPID%
      WinMove, ahk_pid %WMCPID%, , A_ScreenWidth - (A_ScreenWidth - Wk1Right) - 831, A_ScreenHeight - (A_ScreenHeight - Wk1Bottom) - 495, 831, 495
      cycle = 3
      return
   }
   if cycle = 3 ; small window without borders, bottom-right of primary monitor
   {
      WinSet, Style, -0xC40000, ahk_pid %WMCPID%
      WinMove, ahk_pid %WMCPID%, , A_ScreenWidth - (A_ScreenWidth - Wk1Right) - 831, A_ScreenHeight - (A_ScreenHeight - Wk1Bottom) - 467, 831, 467
      cycle = 4
      return
   }
   if cycle = 4 ; virtual full-screen on secondary monitor
   {
      WinSet, Style, -0xC40000, ahk_pid %WMCPID%
      WinMove, ahk_pid %WMCPID%, , Mon2Left, Mon2Top, Mon2W, Mon2H
      cycle = 5
      return
   }

}
Else ; only provides modes for the primary monitor
{
   if cycle in 1,4,5
   {
      WinSet, Style, -0xC40000, ahk_pid %WMCPID%
      WinMove, ahk_pid %WMCPID%, , 0, 0, A_ScreenWidth, A_ScreenHeight
      WinActivate, ahk_pid %WMCPID%
      cycle = 2
      return
   }
   if cycle = 2
   {
      WinSet, Style, +0xC40000, ahk_pid %WMCPID%
      WinMove, ahk_pid %WMCPID%, , A_ScreenWidth - (A_ScreenWidth - Wk1Right) - 831, A_ScreenHeight - (A_ScreenHeight - Wk1Bottom) - 495, 831, 495
      cycle = 3
      return
   }
   if cycle = 3
   {
      WinSet, Style, -0xC40000, ahk_pid %WMCPID%
      WinMove, ahk_pid %WMCPID%, , A_ScreenWidth - (A_ScreenWidth - Wk1Right) - 831, A_ScreenHeight - (A_ScreenHeight - Wk1Bottom) - 467, 831, 467
      cycle = 4
      return
   }
}
return

; Mutes Windows Media Center independently using Vista's Volume Mixer
#IfWinExist, ahk_class eHome Render Window
sc120:: ; scancode for the Mute key
Process, Exist, SndVol.exe
SndVolPID = %ErrorLevel%
If SndVolPID = 0
   {
      Run, SndVol.exe, , , SndVolPID
      Sleep, 120
   }
;ControlSend, ToolbarWindow326, {Space}, SndVol.exe ; Toggles the mute control for Media Center
ControlFocus, Mute for Windows Media Center, ahk_pid %SndVolPID%
ControlSend, Mute for Windows Media Center, {Space}, ahk_pid %SndVolPID%
;MsgBox, %ErrorLevel%
return

/*
The following subroutines hide the cursor (placing it in the bottom left corner of the primary monitor)
when it idles over the Media Center window for ~5 seconds, and then returns it to the previous coordinates when the
user begins to move the mouse again.
*/
MouseHideOn:
SetTimer, WaitForMouseIdle, On
return

MouseHideOff:
SetTimer, WaitForMouseIdle, Off
SetTimer, WaitForMouseMove, Off
DllCall("SetCursorPos", int, PosX1, int, PosY1) ; A DllCall is more reliable than MouseMove in multi-monitor setups
return

WaitForMouseIdle:
if A_TimeIdle > 5000
{
   MouseGetPos, PosX1, PosY1
   WinGetPos, WMCx, WMCy, WMCw, WMCh, ahk_pid %WMCPID%
   if ((PosX1 > WMCx and PosX1 < WMCx + WMCw) and (PosY1 > WMCy and PosY1 < WMCy + WMCh)) ; Checks if cursor is positioned over the window
   {
      DllCall("SetCursorPos", int, 0, int, A_ScreenHeight) ; Places cursor in bottom-left corner of primary monitor
      MouseGetPos, PosX2, PosY2
      SetTimer, WaitForMouseIdle, Off
      SetTimer, WaitForMouseMove, On
   }
}
return

WaitForMouseMove:
MouseGetPos, PosX3, PosY3
if (PosX3 <> PosX2 or PosY3 <> PosY2)
{
   DllCall("SetCursorPos", int, PosX1, int, PosY1) ; Returns cursor to its previous position
   SetTimer, WaitForMouseMove, Off
   SetTimer, WaitForMouseIdle, On
}
return
Back to top
View user's profile Send private message
samhnky



Joined: 29 Sep 2009
Posts: 75

PostPosted: Mon Oct 19, 2009 2:24 am    Post subject: Disable screen saver? Reply with quote

Is there a way to add code that disables the screen saver while the media center is open... My computer is my TV, so I have run into a problem with this code in that the virtual full screen does not disable the screen saver like the true full screen did...
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group