Since I use a Lenovo V560 with the Hauppauge WinTV-DualHD Dual USB 2.0 HD TV Tuner for Windows and Windows Media Center on Windows 7, it occurred to me that I could use a AHK script with an IR transmitter to trigger the shutdown. So I ordered a USB-UIRT from ebay and with the following script I was in business:
Code: Select all
#SingleInstance Force
settimer, PowerCheck, 1000 ;Check power once a second (could be longer)
!x:: ;Exit App Hotkey
ExitApp
PowerCheck:
VarSetCapacity(powerstatus, 1+1+1+1+4+4)
success := DllCall("kernel32.dll\GetSystemPowerStatus", "uint", &powerstatus)
acLineStatus:=ReadInteger(&powerstatus,0,1,false)
;batteryFlag:=ReadInteger(&powerstatus,1,1,false) ;Used for other issues
;batteryLifePercent:=ReadInteger(&powerstatus,2,1,false)
;batteryLifeTime:=ReadInteger(&powerstatus,4,4,false)
;batteryFullLifeTime:=ReadInteger(&powerstatus,8,4,false)
;tooltip OffTime: %OffTime% `n acLineStatus: %acLineStatus%, 500,100 ;testing
if (acLineStatus <> 1)
OffTime++
else
OffTime := 0
If (OffTime > 60) ;Allow 1 minute in case power fail is momentary
{
PowerFailFlag := 1 ;Set Power Fail Flag used for orderly shutdown in case recording
PJoff:
run, C:\uutx "0000 006D 0000 0022 0157 00AC 0016 0041 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0015 0016 0041 0016 0015 0016 0015 0016 0041 0016 0015 0016 0041 0016 0041 0016 0041 0016 0041 0016 0015 0016 0041 0016 0041 0016 0041 0016 0015 0016 0015 0016 0041 0016 0016 0016 0041 0016 0016 0016 0016 0016 0016 0016 0041 0016 0041 0016 0016 0016 0040 0016 05D3"
sleep 1000 ;Must send twice for PJ to shutdown
run, C:\uutx "0000 006D 0000 0022 0157 00AC 0016 0041 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0015 0016 0041 0016 0015 0016 0015 0016 0041 0016 0015 0016 0041 0016 0041 0016 0041 0016 0041 0016 0015 0016 0041 0016 0041 0016 0041 0016 0015 0016 0015 0016 0041 0016 0016 0016 0041 0016 0016 0016 0016 0016 0016 0016 0041 0016 0041 0016 0016 0016 0040 0016 05D3"
}
return
ExitApp
ReadInteger( p_address, p_offset, p_size, p_hex=true )
{
value = 0
old_FormatInteger := a_FormatInteger
if ( p_hex )
SetFormat, integer, hex
else
SetFormat, integer, dec
loop, %p_size%
value := value+( *( ( p_address+p_offset )+( a_Index-1 ) ) << ( 8* ( a_Index-1 ) ) )
SetFormat, integer, %old_FormatInteger%
return, value
}
To get the code the projector required to initiate the shutdown I used an app lrnhelper which allow you to point the remote at the USB-UIRT and learn the button code. The copy and paste into your AHK script.
There is also the possibility to submit a file containing all of your remote codes in a .txt file and invoke the send like this:
run, C:\uutx -f<filename.txt> <IRCodeName> Example: run, C:\uutx C:\remote\codes.txt play
The function is case sensitive, so play and PLAY are different.
In the file the codes are entered like this:
; Format: <IRCodeName> <IRCode> (you can add comments in the file with ; )
play 0000 0067 0000 0004 0011 0011 0022 0022 0011 0022 0011 0387
pause 0000 0067 0000 0004 0011 0011 0022 0022 0011 0022 0011 0388
Use tabs after the IRcodeName then the learned code
For other control by an AHK script will be a matter of calling the uutx app with the appropriate filename and IRCodeName.
To download the USB-UIRT driver goto the USB-UIRT webpage at http://www.usbuirt.com/getstart.htm and select the Windows system you have. Use the i386 folder.
To download the uutx app here is the download link: http://www.etcwiki.org/dl/uutx_0_3.zip
To download the lrnhelper apphttp://www.usbuirt.com/lrnhelper_0_0_5.zip
You will also need the uuirtdrv.dll file available in the i386 folder for the driver.
Once installed the uuirtdrv.dll should be moved from the i386 folder to C:\WINDOWS\system32\
Once the USB-UIRT driver is downloaded, the driver is installed using the device manager per the instructions on the USB-UIRT getstart page.