Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #cs
- BitByteBit
- AlienUDF: http://pastebin.com/i09q5ruP
- Array Structure.
- [n][0] = Device
- [n][1] = Function
- [n][2] = Range
- [n][3] = Colour
- [n][4] = State
- [n][5] = List Item Handle.
- #ce
- FileInstall('LightFX 64x.dll', 'LightFX 64x.dll')
- #include<Array.au3>
- #include<guitreeview.au3>
- #include<guilistview.au3>
- Global $aInfo[4], $hWnd, $hGUI1
- Global $hCombo1, $hCombo2, $hCombo3
- Global $aControl[1][6]
- Global $hCPU1, $hCPU2, $hGPU, $hBat
- Global $hCtrl, $hIntel1, $hIntel2, $nVidia, $bChanged = False, $bHwHidden = False, $bSimulate = False, $bHidden = False
- Global Const $sStr = StringSplit("Battery|CPU|GPU", "|", 2), $aDev = StringSplit("Keyboard|Left Grill|Right Grill|Logo|Status", "|", 2), $hFile = @ScriptDir & '\Options.ini'
- $aControl[0][0] = 0
- _StartHWMonitor()
- Global $aSettings
- OnAutoItExitRegister('_Exit')
- Opt("GUIResizeMode", 1)
- Opt("GUIOnEventMode", 1)
- Opt("TrayIconDebug", 1)
- Opt('TrayAutoPause', 0)
- Opt('TrayOnEventMode', 1)
- Opt('TrayMenuMode', 1)
- $HW = TrayCreateItem('Hide HWMonitor')
- TrayCreateItem('Exit')
- TrayItemSetOnEvent(-1, '_Exit')
- TraySetClick(8)
- TraySetOnEvent(-7, '_HideMain')
- TrayItemSetOnEvent($HW, '_HideHWMonitor')
- AdlibRegister('_EnsureOpen', 3000)
- AdlibRegister('_ReduceMemory', 10000)
- _ReduceMemory()
- HotKeySet('!d', '_Debug')
- Func _Debug()
- _ArrayDisplay($aControl)
- EndFunc ;==>_Debug
- #region GUI
- $GUI_EVENT_CLOSE = -3
- $hGUI = GUICreate("Templien V2", 436, 325, -1, -1, 0x00040000 + 0x00010000 + 0x00020000)
- GUISetOnEvent(-3, '_Exit')
- GUISetBkColor(0x1F1F1F)
- GUICtrlCreateGroup("", 5, 18, 424, 277)
- $hDevice = GUICtrlCreateList("", 12, 31, 92, 57)
- $hFunction = GUICtrlCreateList("", 12, 88, 92, 57)
- $hRange = GUICtrlCreateList("", 12, 145, 92, 57)
- $hColour = GUICtrlCreateList("", 12, 202, 92, 57)
- GUICtrlSetData($hDevice, "Keyboard|Left Grill|Right Grill|Logo|Status")
- GUICtrlSetData($hFunction, "CPU|GPU|Battery")
- GUICtrlSetData($hColour, "Custom|Blue|Green|Indigo|Red|Orange|Violet|Yellow|White")
- $List1 = GUICtrlCreateListView("Light |Function|Range|Colour", 114, 31, 308, 255, 0x0010, 0x00000004 + 0x00000020)
- $Button1 = GUICtrlCreateButton("Add", 12, 262, 42, 25)
- $Button2 = GUICtrlCreateButton("Delete", 62, 262, 42, 25)
- GUICtrlSetOnEvent($Button1, '_Save')
- GUICtrlSetOnEvent($Button2, '_Delete')
- For $iTmp = 0 To 90 Step 10
- If $iTmp = 90 Then
- GUICtrlSetData($hRange, $iTmp & " - " & 100)
- Else
- GUICtrlSetData($hRange, $iTmp & " - " & $iTmp + 9)
- EndIf
- Next
- _LoadSettings()
- $iTmp = GUICtrlCreateLabel("Loading AlienFX libary.", 162, 5, 112, 15)
- GUICtrlSetColor($iTmp, 0xFFFFFF)
- GUICtrlSetResizing($iTmp, 768)
- GUISetState(@SW_SHOW)
- #include<AlienUDF.au3>
- GUICtrlDelete($iTmp)
- $iTmp = GUICtrlCreateLabel("Core 1", 42, 5, 35, 15)
- GUICtrlCreateLabel("Core 2", 138, 5, 37, 15)
- GUICtrlCreateLabel("GPU", 234, 5, 29, 15)
- $hCPU1 = GUICtrlCreateLabel("0c", 82, 5, 30, 15)
- $hCPU2 = GUICtrlCreateLabel("0c", 178, 5, 30, 15)
- $hGPU = GUICtrlCreateLabel("0", 274, 5, 30, 15)
- $hBat = GUICtrlCreateLabel("100%", 370, 5, 30, 15)
- For $iTmp = $iTmp To GUICtrlCreateLabel("Battery", 330, 5, 37, 15)
- GUICtrlSetColor($iTmp, 0xFFFFFF)
- GUICtrlSetResizing($iTmp, 768)
- GUICtrlSetOnEvent($iTmp, '_Simulate')
- Next
- #endregion ### END Koda GUI section ###
- While 1
- If Not $bSimulate Then
- $aInfo[0] = _GetBattery()
- $aInfo[1] = Int(_StringBetween1(_GUICtrlTreeView_GetText($hCtrl, $hIntel1), ' ', ' °C ('))
- $aInfo[2] = Int(_StringBetween1(_GUICtrlTreeView_GetText($hCtrl, $nVidia), ' ', ' °C ('))
- $aInfo[3] = Int(_StringBetween1(_GUICtrlTreeView_GetText($hCtrl, $hIntel2), ' ', ' °C ('))
- EndIf
- ;~ $aInfo[0] = ControlGetText('Form1', '', 'Static1')
- ;~ $aInfo[1] = $aInfo[0]
- ;~ $aInfo[2] = $aInfo[0]
- ;~ $aInfo[3] = $aInfo[0]
- If $aInfo[0] <> GUICtrlRead($hBat) Then GUICtrlSetData($hBat, $aInfo[0])
- If $aInfo[1] <> GUICtrlRead($hCPU1) Then GUICtrlSetData($hCPU1, $aInfo[1])
- If $aInfo[3] <> GUICtrlRead($hCPU2) Then GUICtrlSetData($hCPU2, $aInfo[3])
- If $aInfo[2] <> GUICtrlRead($hGPU) Then GUICtrlSetData($hGPU, $aInfo[2])
- _CheckDevice()
- ;~ $nMsg = GUIGetMsg()
- ;~ Switch $nMsg
- ;~ Case $GUI_EVENT_CLOSE
- ;~ Exit
- ;~ Case $Button1
- ;~ _Save()
- ;~ Case $Button2
- ;~ _Delete()
- ;~ EndSwitch
- Sleep(500)
- WEnd
- Func _CheckDevice()
- ;_AlienSetLightColour($iColour = 0xFF0000FF, $iLight = 0, $iLocation = 0)
- ;0 - Keyboard.
- ;1 - Left Grill.
- ;2 - Right Grill.
- ;3 - Logo.
- ;4 - Status.
- ;Loop through all rules.
- For $i = 1 To $aControl[0][0]
- Switch $aControl[$i][1]
- Case $sStr[0]
- $x = 0
- Case $sStr[1]
- $x = 1
- Case $sStr[2]
- $x = 2
- EndSwitch
- $aRange = StringSplit($aControl[$i][2], " - ", 1)
- ;If within range.
- If $aInfo[$x] >= $aRange[1] And $aInfo[$x] <= $aRange[2] Then
- ;If already on ignore.
- If $aControl[$i][4] = 'On' Then ContinueLoop
- ;Get light device.
- For $iDev = 0 To 4
- If $aControl[$i][0] = $aDev[$iDev] Then ExitLoop
- Next
- ;Set variable to On.
- $aControl[$i][4] = 'On'
- $bChanged = True
- ;Enable Checkbox.
- GUICtrlSetState($aControl[$i][5], 1)
- ;Turn on light.
- _AlienSetLightColour('0xFF' & $aControl[$i][3], $iDev)
- ElseIf $aControl[$i][4] = 'On' Then
- GUICtrlSetState($aControl[$i][5], 4)
- $aControl[$i][4] = 'Off'
- EndIf
- Next
- If $bChanged Then
- _AlienUpdate()
- $bChanged = False
- ;ConsoleWrite('Updated.' & @CRLF)
- EndIf
- EndFunc ;==>_CheckDevice
- Func _ChooseColor($iReturnType = 2, $iColorRef = 0, $iRefType = 0, $hWndOwnder = 0)
- Local $custcolors = "dword[16]"
- Local $tChoose = DllStructCreate("dword Size;hwnd hWndOwnder;handle hInstance;dword rgbResult;ptr CustColors;dword Flags;lparam lCustData;ptr lpfnHook;ptr lpTemplateName")
- Local $tcc = DllStructCreate($custcolors)
- If $iRefType = 1 Then ; BGR hex color to colorref
- $iColorRef = Int($iColorRef)
- ElseIf $iRefType = 2 Then ; RGB hex color to colorref
- $iColorRef = Hex(String($iColorRef), 6)
- $iColorRef = '0x' & StringMid($iColorRef, 5, 2) & StringMid($iColorRef, 3, 2) & StringMid($iColorRef, 1, 2)
- EndIf
- DllStructSetData($tChoose, "Size", DllStructGetSize($tChoose))
- DllStructSetData($tChoose, "hWndOwnder", $hWndOwnder)
- DllStructSetData($tChoose, "rgbResult", $iColorRef)
- DllStructSetData($tChoose, "CustColors", DllStructGetPtr($tcc))
- DllStructSetData($tChoose, "Flags", BitOR(0x0100, 0x0002, 0x0001))
- Local $aResult = DllCall("comdlg32.dll", "bool", "ChooseColor", "ptr", DllStructGetPtr($tChoose))
- If @error Then Return SetError(@error, @extended, -1)
- If $aResult[0] = 0 Then Return SetError(-3, -3, -1) ; user selected cancel or struct settings incorrect
- Local $color_picked = DllStructGetData($tChoose, "rgbResult")
- If $iReturnType = 1 Then ; return Hex BGR Color
- Return '0x' & Hex(String($color_picked), 6)
- ElseIf $iReturnType = 2 Then ; return Hex RGB Color
- $color_picked = Hex(String($color_picked), 6)
- Return StringMid($color_picked, 5, 2) & StringMid($color_picked, 3, 2) & StringMid($color_picked, 1, 2)
- ElseIf $iReturnType = 0 Then ; return RGB COLORREF
- Return $color_picked
- Else
- Return SetError(-4, -4, -1)
- EndIf
- EndFunc ;==>_ChooseColor
- Func _Delete()
- $sCurrent = GUICtrlRead($List1)
- If $sCurrent = 0 Then Return MsgBox(48, 'Error', 'Please select a profile on the right.')
- For $i = 1 To $aControl[0][0]
- If $sCurrent = $aControl[$i][5] Then
- GUICtrlDelete($aControl[$i][5])
- IniDelete($hFile, 'Profiles', $aControl[$i][0] & '|' & $aControl[$i][1] & '|' & $aControl[$i][2] & '|' & $aControl[$i][3])
- _ArrayDelete($aControl, $i)
- $aControl[0][0] -= 1
- ExitLoop
- EndIf
- Next
- EndFunc ;==>_Delete
- Func _EndSimulation()
- $bSimulate = False
- GUIDelete($hGUI1)
- EndFunc ;==>_EndSimulation
- Func _EnsureOpen()
- If Not ProcessExists('HWMonitor.exe') Then _StartHWMonitor()
- EndFunc ;==>_EnsureOpen
- Func _Exit()
- WinClose('CPUID')
- _AlienClose()
- Exit
- EndFunc ;==>_Exit
- Func _HideHWMonitor()
- $bHwHidden = $bHwHidden = False
- If $bHwHidden Then
- WinSetState($hWnd, '', @SW_HIDE)
- Else
- WinSetState($hWnd, '', @SW_SHOW)
- EndIf
- EndFunc ;==>_HideHWMonitor
- Func _HideMain()
- $bHidden = $bHidden = False
- If $bHidden Then
- GUISetState(@SW_SHOW, $hGUI)
- Else
- GUISetState(@SW_HIDE, $hGUI)
- EndIf
- EndFunc ;==>_HideMain
- Func _IniWrite($i)
- IniWrite($hFile, 'Profiles', $aControl[$i][0] & '|' & $aControl[$i][1] & '|' & $aControl[$i][2] & '|' & $aControl[$i][3], '')
- EndFunc ;==>_IniWrite
- Func _ListItemHandler()
- $sTmp = GUICtrlRead(@GUI_CtrlId)
- $sTmp = StringSplit($sTmp, '|')
- GUICtrlSetData($hDevice, $sTmp[1])
- GUICtrlSetData($hFunction, $sTmp[2])
- GUICtrlSetData($hRange, $sTmp[3])
- GUICtrlSetData($hColour, $sTmp[4])
- EndFunc ;==>_ListItemHandler
- Func _LoadSettings()
- $aSettings = IniReadSection($hFile, 'Profiles')
- If @error Then
- Global $aControl[1][6]
- $aControl[0][0] = 0
- Return
- EndIf
- ReDim $aControl[$aSettings[0][0] + 1][6]
- $aControl[0][0] = $aSettings[0][0]
- For $i = 1 To $aSettings[0][0]
- $aArray = StringSplit($aSettings[$i][0], '|')
- $aControl[$i][0] = $aArray[1]
- $aControl[$i][1] = $aArray[2]
- $aControl[$i][2] = $aArray[3]
- $aControl[$i][3] = $aArray[4]
- $aControl[$i][4] = 'Off'
- $aControl[$i][5] = GUICtrlCreateListViewItem($aControl[$i][0] & '|' & $aControl[$i][1] & '|' & $aControl[$i][2] & '|' & _RGBToString($aArray[4]), $List1)
- GUICtrlSetOnEvent($aControl[$i][5], '_ListItemHandler')
- Next
- ;_ArrayDisplay($aControl)
- EndFunc ;==>_LoadSettings
- Func _ReduceMemory()
- ;~ _Log('Reducing memory.')
- Local $ai = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', @AutoItPID)
- $ai = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai[0])
- DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai[0])
- EndFunc ;==>_ReduceMemory
- Func _RGBToString($sStr1)
- Switch $sStr1
- Case '0000FF'
- $sStr1 = 'Blue'
- Case '00FF00'
- $sStr1 = "Green"
- Case 'FF0000'
- $sStr1 = "Red"
- Case '3F48CC'
- $sStr1 = 'Indigo'
- Case 'FF8000'
- $sStr1 = 'Orange'
- Case '8000FF'
- $sStr1 = 'Violet'
- Case 'FFFFFF'
- $sStr1 = "White"
- Case Else
- $sStr1 = 'Custom'
- EndSwitch
- Return $sStr1
- EndFunc ;==>_RGBToString
- Func _Save()
- Local $iDevice, $iFunction, $iRange, $iColour
- $iDevice = GUICtrlRead($hDevice)
- $iFunction = GUICtrlRead($hFunction)
- $iRange = GUICtrlRead($hRange)
- $iColor = GUICtrlRead($hColour)
- If Not $iDevice Then
- ;ConsoleWrite($iDevice & @CRLF)
- Return MsgBox(48, 'Error T__T', 'Please choose a light!')
- ElseIf Not $iFunction Then
- Return MsgBox(48, 'Error T__T', 'Please choose a function!')
- ElseIf Not $iRange Then
- Return MsgBox(48, 'Error T__T', 'Please choose a range!')
- ElseIf Not $iColor Then
- Return MsgBox(48, 'Error T__T', 'Please choose a colour!')
- EndIf
- $iU = UBound($aControl)
- $aControl[0][0] += 1
- ReDim $aControl[$iU + 1][6]
- $aControl[$iU][0] = $iDevice
- $aControl[$iU][1] = $iFunction
- $aControl[$iU][2] = $iRange
- Switch $iColor
- Case "Custom"
- $aControl[$iU][3] = _ChooseColor()
- Case "Blue"
- $aControl[$iU][3] = '0000FF'
- Case "Green"
- $aControl[$iU][3] = '00FF00'
- Case "Indigo"
- $aControl[$iU][3] = '3F48CC'
- Case "Red"
- $aControl[$iU][3] = 'FF0000'
- Case "Orange"
- $aControl[$iU][3] = 'FF8000'
- Case "Violet"
- $aControl[$iU][3] = '8000FF'
- Case "White"
- $aControl[$iU][3] = 'FFFFFF'
- Case "Yellow"
- $aControl[$iU][3] = 'FFFF00'
- Case Else
- EndSwitch
- $aControl[$iU][4] = 'Off'
- $aControl[$iU][5] = GUICtrlCreateListViewItem($aControl[$iU][0] & '|' & $aControl[$iU][1] & '|' & $aControl[$iU][2] & '|' & GUICtrlRead($hColour), $List1)
- GUICtrlSetOnEvent($aControl[$iU][5], '_ListItemHandler')
- _IniWrite($iU)
- ;_ArrayDisplay($aControl)
- EndFunc ;==>_Save
- Func _Simulate()
- $bSimulate = True
- $hGUI1 = GUICreate('Simulating.', 107, 91, Default, Default, Default, 0x00000080)
- GUISetOnEvent(-3, '_EndSimulation')
- GUISetBkColor(0x1F1F1F)
- $hCombo1 = GUICtrlCreateCombo('0', 55, 10, 42)
- GUICtrlSetOnEvent(-1, '_SimulateCombo')
- $hCombo2 = GUICtrlCreateCombo('0', 55, 35, 42)
- GUICtrlSetOnEvent(-1, '_SimulateCombo')
- $hCombo3 = GUICtrlCreateCombo('0', 55, 60, 42)
- GUICtrlSetOnEvent(-1, '_SimulateCombo')
- For $i = 0 To 100 Step 10
- GUICtrlSetData($hCombo1, $i, $aInfo[1])
- GUICtrlSetData($hCombo2, $i, $aInfo[2])
- GUICtrlSetData($hCombo3, $i, $aInfo[0])
- Next
- GUICtrlCreateLabel('CPU', 10, 14)
- GUICtrlSetColor(-1, 0xFFFFFF)
- GUICtrlCreateLabel('GPU', 10, 39)
- GUICtrlSetColor(-1, 0xFFFFFF)
- GUICtrlCreateLabel('Battery', 10, 64)
- GUICtrlSetColor(-1, 0xFFFFFF)
- GUISetState(@SW_SHOW, $hGUI1)
- EndFunc ;==>_Simulate
- Func _SimulateCombo()
- Switch @GUI_CtrlId
- Case $hCombo1
- ;CPU
- $aInfo[1] = GUICtrlRead($hCombo1)
- $aInfo[3] = $aInfo[1]
- Case $hCombo2
- ;GPU
- $aInfo[2] = GUICtrlRead($hCombo2)
- Case $hCombo3
- ;Battery
- $aInfo[0] = GUICtrlRead($hCombo3)
- EndSwitch
- EndFunc ;==>_SimulateCombo
- Func _StartHWMonitor()
- If Not ProcessExists('hwmonitor.exe') Then
- If ShellExecute(@ScriptDir & '\HWMonitor.exe', '', '', '', @SW_HIDE) = 0 Then Exit MsgBox(0, 'FATALITY!', 'Failed to find: "HWMonitor.exe"' & @CR & 'In folder: ' & @ScriptDir & @CR & 'Please relocate Templien.exe to a folder that contains HWMonitor.')
- EndIf
- WinWait('CPUID Hardware Monitor')
- $hWnd = WinGetHandle('CPUID Hardware Monitor')
- $hCtrl = ControlGetHandle($hWnd, '', 'SysTreeView321')
- ControlListView($hWnd, '', 'SysTreeView321', 'SelectAll')
- $hIntel1 = _GUICtrlTreeView_FindItem($hCtrl, "Intel", True, 0)
- If $hIntel1 = 0 Then
- MsgBox(0, 'Error T__T', 'Failed to read CPU temperature.' & @CRLF & 'Please send a screenshot of HWMonitor to [email protected].')
- Else
- $hIntel1 = _GUICtrlTreeView_GetFirstChild($hCtrl, _GUICtrlTreeView_GetFirstChild($hCtrl, $hIntel1))
- $hIntel2 = _GUICtrlTreeView_GetNextSibling($hCtrl, $hIntel1)
- EndIf
- $nVidia = _GUICtrlTreeView_FindItem($hCtrl, "NVIDIA", True, 0)
- If $nVidia = 0 Then
- Return ;MsgBox(0, 'Error T__T', 'Failed to read GPU temperature.' & @CR & 'Please enable graphics card then close HWMonitor.')
- Else
- $nVidia = _GUICtrlTreeView_GetFirstChild($hCtrl, _GUICtrlTreeView_GetNextSibling($hCtrl, _GUICtrlTreeView_GetFirstChild($hCtrl, $nVidia)))
- EndIf
- If $bHwHidden Then WinSetState($hWnd, '', @SW_HIDE)
- EndFunc ;==>_StartHWMonitor
- Func _StringBetween1($s_String, $s_Start = 0, $s_End = 0)
- $s_Start = StringInStr($s_String, $s_Start) + StringLen($s_Start)
- Return StringMid($s_String, $s_Start, StringInStr($s_String, $s_End) - $s_Start)
- EndFunc ;==>_StringBetween1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement