求大神帮我转换 AHK 代码为 AU3
下面的代码是用来调节笔记本显示屏亮度的,它有个好处是,调节亮度的时候,有OSD显示。求大神帮我转换成AU3代码,不胜感激!用法:
brightness 3 ;在原有亮度基础上增加3档
brightness -2 ;在原有亮度基础上降低2档
#singleinstance,force
#NoTrayIcon
value=%1%
BS := new BrightnessSetter()
BS.SetBrightness(value)
Exitapp
class BrightnessSetter {
; qwerty12 - 27/05/17
; https://github.com/qwerty12/AutoHotkeyScripts/tree/master/LaptopBrightnessSetter
static _WM_POWERBROADCAST := 0x218, _osdHwnd := 0, hPowrprofMod := DllCall("LoadLibrary", "Str", "powrprof.dll", "Ptr")
__New() {
if (BrightnessSetter.IsOnAc(AC))
this._AC := AC
if ((this.pwrAcNotifyHandle := DllCall("RegisterPowerSettingNotification", "Ptr", A_ScriptHwnd, "Ptr", BrightnessSetter._GUID_ACDC_POWER_SOURCE(), "UInt", DEVICE_NOTIFY_WINDOW_HANDLE := 0x00000000, "Ptr"))) ; Sadly the callback passed to *PowerSettingRegister*Notification runs on a new threadl
OnMessage(this._WM_POWERBROADCAST, ((this.pwrBroadcastFunc := ObjBindMethod(this, "_On_WM_POWERBROADCAST"))))
}
__Delete() {
if (this.pwrAcNotifyHandle) {
OnMessage(BrightnessSetter._WM_POWERBROADCAST, this.pwrBroadcastFunc, 0)
,DllCall("UnregisterPowerSettingNotification", "Ptr", this.pwrAcNotifyHandle)
,this.pwrAcNotifyHandle := 0
,this.pwrBroadcastFunc := ""
}
}
SetBrightness(increment, jump := False, showOSD := True, autoDcOrAc := -1, ptrAnotherScheme := 0)
{
static PowerGetActiveScheme := DllCall("GetProcAddress", "Ptr", BrightnessSetter.hPowrprofMod, "AStr", "PowerGetActiveScheme", "Ptr")
,PowerSetActiveScheme := DllCall("GetProcAddress", "Ptr", BrightnessSetter.hPowrprofMod, "AStr", "PowerSetActiveScheme", "Ptr")
,PowerWriteACValueIndex := DllCall("GetProcAddress", "Ptr", BrightnessSetter.hPowrprofMod, "AStr", "PowerWriteACValueIndex", "Ptr")
,PowerWriteDCValueIndex := DllCall("GetProcAddress", "Ptr", BrightnessSetter.hPowrprofMod, "AStr", "PowerWriteDCValueIndex", "Ptr")
,PowerApplySettingChanges := DllCall("GetProcAddress", "Ptr", BrightnessSetter.hPowrprofMod, "AStr", "PowerApplySettingChanges", "Ptr")
if (increment == 0 && !jump) {
if (showOSD)
BrightnessSetter._ShowBrightnessOSD()
return
}
if (!ptrAnotherScheme ? DllCall(PowerGetActiveScheme, "Ptr", 0, "Ptr*", currSchemeGuid, "UInt") == 0 : DllCall("powrprof\PowerDuplicateScheme", "Ptr", 0, "Ptr", ptrAnotherScheme, "Ptr*", currSchemeGuid, "UInt") == 0) {
if (autoDcOrAc == -1) {
if (this != BrightnessSetter) {
AC := this._AC
} else {
if (!BrightnessSetter.IsOnAc(AC)) {
DllCall("LocalFree", "Ptr", currSchemeGuid, "Ptr")
return
}
}
} else {
AC := !!autoDcOrAc
}
currBrightness := 0
if (jump || BrightnessSetter._GetCurrentBrightness(currSchemeGuid, AC, currBrightness)) {
maxBrightness := BrightnessSetter.GetMaxBrightness()
,minBrightness := BrightnessSetter.GetMinBrightness()
if (jump || !((currBrightness == maxBrightness && increment > 0) || (currBrightness == minBrightness && increment < minBrightness))) {
if (currBrightness + increment > maxBrightness)
increment := maxBrightness
else if (currBrightness + increment < minBrightness)
increment := minBrightness
else
increment += currBrightness
if (DllCall(AC ? PowerWriteACValueIndex : PowerWriteDCValueIndex, "Ptr", 0, "Ptr", currSchemeGuid, "Ptr", BrightnessSetter._GUID_VIDEO_SUBGROUP(), "Ptr", BrightnessSetter._GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS(), "UInt", increment, "UInt") == 0) {
; PowerApplySettingChanges is undocumented and exists only in Windows 8+. Since both the Power control panel and the brightness slider use this, we'll do the same, but fallback to PowerSetActiveScheme if on Windows 7 or something
if (!PowerApplySettingChanges || DllCall(PowerApplySettingChanges, "Ptr", BrightnessSetter._GUID_VIDEO_SUBGROUP(), "Ptr", BrightnessSetter._GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS(), "UInt") != 0)
DllCall(PowerSetActiveScheme, "Ptr", 0, "Ptr", currSchemeGuid, "UInt")
}
}
if (showOSD)
BrightnessSetter._ShowBrightnessOSD()
}
DllCall("LocalFree", "Ptr", currSchemeGuid, "Ptr")
}
}
IsOnAc(ByRef acStatus)
{
static SystemPowerStatus
if (!VarSetCapacity(SystemPowerStatus))
VarSetCapacity(SystemPowerStatus, 12)
if (DllCall("GetSystemPowerStatus", "Ptr", &SystemPowerStatus)) {
acStatus := NumGet(SystemPowerStatus, 0, "UChar") == 1
return True
}
return False
}
GetDefaultBrightnessIncrement()
{
static ret := 10
DllCall("powrprof\PowerReadValueIncrement", "Ptr", BrightnessSetter._GUID_VIDEO_SUBGROUP(), "Ptr", BrightnessSetter._GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS(), "UInt*", ret, "UInt")
return ret
}
GetMinBrightness()
{
static ret := -1
if (ret == -1)
if (DllCall("powrprof\PowerReadValueMin", "Ptr", BrightnessSetter._GUID_VIDEO_SUBGROUP(), "Ptr", BrightnessSetter._GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS(), "UInt*", ret, "UInt"))
ret := 0
return ret
}
GetMaxBrightness()
{
static ret := -1
if (ret == -1)
if (DllCall("powrprof\PowerReadValueMax", "Ptr", BrightnessSetter._GUID_VIDEO_SUBGROUP(), "Ptr", BrightnessSetter._GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS(), "UInt*", ret, "UInt"))
ret := 100
return ret
}
_GetCurrentBrightness(schemeGuid, AC, ByRef currBrightness)
{
static PowerReadACValueIndex := DllCall("GetProcAddress", "Ptr", BrightnessSetter.hPowrprofMod, "AStr", "PowerReadACValueIndex", "Ptr")
,PowerReadDCValueIndex := DllCall("GetProcAddress", "Ptr", BrightnessSetter.hPowrprofMod, "AStr", "PowerReadDCValueIndex", "Ptr")
return DllCall(AC ? PowerReadACValueIndex : PowerReadDCValueIndex, "Ptr", 0, "Ptr", schemeGuid, "Ptr", BrightnessSetter._GUID_VIDEO_SUBGROUP(), "Ptr", BrightnessSetter._GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS(), "UInt*", currBrightness, "UInt") == 0
}
_ShowBrightnessOSD()
{
static PostMessagePtr := DllCall("GetProcAddress", "Ptr", DllCall("GetModuleHandle", "Str", "user32.dll", "Ptr"), "AStr", A_IsUnicode ? "PostMessageW" : "PostMessageA", "Ptr")
,WM_SHELLHOOK := DllCall("RegisterWindowMessage", "Str", "SHELLHOOK", "UInt")
if A_OSVersion in WIN_VISTA,WIN_7
return
BrightnessSetter._RealiseOSDWindowIfNeeded()
; Thanks to YashMaster @ https://github.com/YashMaster/Tweaky/blob/master/Tweaky/BrightnessHandler.h for realising this could be done:
if (BrightnessSetter._osdHwnd)
DllCall(PostMessagePtr, "Ptr", BrightnessSetter._osdHwnd, "UInt", WM_SHELLHOOK, "Ptr", 0x37, "Ptr", 0)
}
_RealiseOSDWindowIfNeeded()
{
static IsWindow := DllCall("GetProcAddress", "Ptr", DllCall("GetModuleHandle", "Str", "user32.dll", "Ptr"), "AStr", "IsWindow", "Ptr")
if (!DllCall(IsWindow, "Ptr", BrightnessSetter._osdHwnd) && !BrightnessSetter._FindAndSetOSDWindow()) {
BrightnessSetter._osdHwnd := 0
try if ((shellProvider := ComObjCreate("{C2F03A33-21F5-47FA-B4BB-156362A2F239}", "{00000000-0000-0000-C000-000000000046}"))) {
try if ((flyoutDisp := ComObjQuery(shellProvider, "{41f9d2fb-7834-4ab6-8b1b-73e74064b465}", "{41f9d2fb-7834-4ab6-8b1b-73e74064b465}"))) {
DllCall(NumGet(NumGet(flyoutDisp+0)+3*A_PtrSize), "Ptr", flyoutDisp, "Int", 0, "UInt", 0)
,ObjRelease(flyoutDisp)
}
ObjRelease(shellProvider)
if (BrightnessSetter._FindAndSetOSDWindow())
return
}
; who knows if the SID & IID above will work for future versions of Windows 10 (or Windows 8). Fall back to this if needs must
Loop 2 {
SendEvent {Volume_Mute 2}
if (BrightnessSetter._FindAndSetOSDWindow())
return
Sleep 100
}
}
}
_FindAndSetOSDWindow()
{
static FindWindow := DllCall("GetProcAddress", "Ptr", DllCall("GetModuleHandle", "Str", "user32.dll", "Ptr"), "AStr", A_IsUnicode ? "FindWindowW" : "FindWindowA", "Ptr")
return !!((BrightnessSetter._osdHwnd := DllCall(FindWindow, "Str", "NativeHWNDHost", "Str", "", "Ptr")))
}
_On_WM_POWERBROADCAST(wParam, lParam)
{
;OutputDebug % &this
if (wParam == 0x8013 && lParam && NumGet(lParam+0, 0, "UInt") == NumGet(BrightnessSetter._GUID_ACDC_POWER_SOURCE()+0, 0, "UInt")) { ; PBT_POWERSETTINGCHANGE and a lazy comparison
this._AC := NumGet(lParam+0, 20, "UChar") == 0
return True
}
}
_GUID_VIDEO_SUBGROUP()
{
static GUID_VIDEO_SUBGROUP__
if (!VarSetCapacity(GUID_VIDEO_SUBGROUP__)) {
VarSetCapacity(GUID_VIDEO_SUBGROUP__, 16)
,NumPut(0x7516B95F, GUID_VIDEO_SUBGROUP__, 0, "UInt"), NumPut(0x4464F776, GUID_VIDEO_SUBGROUP__, 4, "UInt")
,NumPut(0x1606538C, GUID_VIDEO_SUBGROUP__, 8, "UInt"), NumPut(0x99CC407F, GUID_VIDEO_SUBGROUP__, 12, "UInt")
}
return &GUID_VIDEO_SUBGROUP__
}
_GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS()
{
static GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS__
if (!VarSetCapacity(GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS__)) {
VarSetCapacity(GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS__, 16)
,NumPut(0xADED5E82, GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS__, 0, "UInt"), NumPut(0x4619B909, GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS__, 4, "UInt")
,NumPut(0xD7F54999, GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS__, 8, "UInt"), NumPut(0xCB0BAC1D, GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS__, 12, "UInt")
}
return &GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS__
}
_GUID_ACDC_POWER_SOURCE()
{
static GUID_ACDC_POWER_SOURCE_
if (!VarSetCapacity(GUID_ACDC_POWER_SOURCE_)) {
VarSetCapacity(GUID_ACDC_POWER_SOURCE_, 16)
,NumPut(0x5D3E9A59, GUID_ACDC_POWER_SOURCE_, 0, "UInt"), NumPut(0x4B00E9D5, GUID_ACDC_POWER_SOURCE_, 4, "UInt")
,NumPut(0x34FFBDA6, GUID_ACDC_POWER_SOURCE_, 8, "UInt"), NumPut(0x486551FF, GUID_ACDC_POWER_SOURCE_, 12, "UInt")
}
return &GUID_ACDC_POWER_SOURCE_
}
}
BrightnessSetter_new() {
return new BrightnessSetter()
}
sanmaodo 发表于 2019-7-21 20:26
明天测试一下,再发上来,谢谢老大了!
通过翻译这个代码,感觉ahk发展比au3快,支持自定义类,有指针操作符 & *,而且com接口与api的调用支持使用指针,虽然au3也支持api的指针调用,但是官方说明是试用命令。
au3近几年的更新,多数是一些修补bug的更新,udf更新,至于au3自身功能的更新几乎是停滞不前。
#NoTrayIcon
#RequireAdmin
#include <WinAPISys.au3>
#include <Array.au3>
Opt('GUIOnEventMode', 1)
Opt('MustDeclareVars', 1)
_GUID_VIDEO_SUBGROUP()
Global Const $GUID_VIDEO_SUBGROUP = '{7516B95F-F776-4464-8C53-06167F40CC99}'
Global Const $GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS = '{ADED5E82-B909-4619-9949-F5D71DAC0BCB}'
Global Const $GUID_ACDC_POWER_SOURCE = '{5D3E9A59-E9D5-4B00-A6BD-FF34FF516548}'
Global Const $WM_POWERBROADCAST = 0x218
Global $hPowrprofMod = _WinAPI_LoadLibrary('powrprof.dll') ;
Global $_AC, $pwrAcNotifyHandle, $_osdHwnd, $currSchemeGuid, $currBrightness, $maxBrightness, $minBrightness
Global $MainForm = GUICreate('', 400, 200)
Global $iLight = GUICtrlCreateSlider(5, 50, 390, 30)
GUISetState()
GUISetOnEvent(-3, '_Exit')
GUICtrlSetOnEvent($iLight, '_SetLight')
__New()
While 1
Sleep(50)
WEnd
Func _SetLight()
SetBrightness(GUICtrlRead($iLight))
EndFunc ;==>_SetLight
Func _Exit()
Exit
EndFunc ;==>_Exit
Func __New()
Local $AC
If IsOnAc($AC) Then $_AC = $AC
$pwrAcNotifyHandle = _WinAPI_RegisterPowerSettingNotification($MainForm, $GUID_ACDC_POWER_SOURCE)
If $pwrAcNotifyHandle Then GUIRegisterMsg($WM_POWERBROADCAST, '_On_WM_POWERBROADCAST')
EndFunc ;==>__New
Func _On_WM_POWERBROADCAST($hwnd, $msg, $wparam, $lparam)
#forceref $hwnd, $msg, $wparam, $lparam
Local Const $PBT_POWERSETTINGCHANGE = 0x8013 ;//已收到电源设置更改事件
Local Const $POWERBROADCAST_SETTING = "ulong Data1;ushort Data2;ushort Data3;byte Data4;dword DataLength;byte Data"
Switch $msg
Case $WM_POWERBROADCAST
Switch $wparam
Case $PBT_POWERSETTINGCHANGE
Local $PBT_PSC = DllStructCreate($POWERBROADCAST_SETTING, $lparam)
If DllStructGetData($PBT_PSC, 1) = DllStructGetData(_GUID_ACDC_POWER_SOURCE(), 1) Then ;//系统电源已更改
$_AC = (DllStructGetData($PBT_PSC, 'Data') = 0)
EndIf
EndSwitch
EndSwitch
Return $_AC
EndFunc ;==>_On_WM_POWERBROADCAST
Func _GUID_VIDEO_SUBGROUP()
Return _WinAPI_GUIDFromString($GUID_VIDEO_SUBGROUP)
EndFunc ;==>_GUID_VIDEO_SUBGROUP
Func _GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS()
Return _WinAPI_GUIDFromString($GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS)
EndFunc ;==>_GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS
Func _GUID_ACDC_POWER_SOURCE()
Return _WinAPI_GUIDFromString($GUID_ACDC_POWER_SOURCE)
EndFunc ;==>_GUID_ACDC_POWER_SOURCE
Func __Delete()
If $pwrAcNotifyHandle Then _WinAPI_UnregisterPowerSettingNotification($pwrAcNotifyHandle)
$pwrAcNotifyHandle = 0
EndFunc ;==>__Delete
Func SetBrightness($increment, $jump = False, $showOSD = True, $autoDcOrAc = -1, $ptrAnotherScheme = 0)
Static $PowerApplySettingChanges = _WinAPI_GetProcAddress($hPowrprofMod, 'PowerApplySettingChanges')
ConsoleWrite('$increment===' & $increment & @CRLF)
If $increment = 0 And Not $jump Then
If $showOSD Then _ShowBrightnessOSD()
Return
EndIf
Local $ActiveScheme = False, $aResult
If Not $ptrAnotherScheme Then
If PowerGetActiveScheme(0, $currSchemeGuid) = 0 Then $ActiveScheme = True
Else
If PowerDuplicateScheme(Null, $ptrAnotherScheme, $currSchemeGuid) = 0 Then $ActiveScheme = True
EndIf
Local $AC = $_AC
If $ActiveScheme Then
If ($autoDcOrAc == -1) Then ;~
If Not IsOnAc($AC) Then Return _WinAPI_LocalFree($currSchemeGuid)
Else
$AC = Not (Not $autoDcOrAc) ;此处应该是类型转化
EndIf
If $jump Or _GetCurrentBrightness($currSchemeGuid, $AC, $currBrightness) Then
$maxBrightness = GetMaxBrightness()
$minBrightness = GetMinBrightness()
If ($jump Or Not (($currBrightness = $maxBrightness And $increment > 0) Or ($currBrightness = $minBrightness And $increment < $minBrightness))) Then
If (($currBrightness + $increment) > $maxBrightness) Then
$increment = $maxBrightness
ElseIf (($currBrightness + $increment) < $minBrightness) Then
$increment = $minBrightness
Else
$increment += $currBrightness
EndIf
If $AC Then
$aResult = PowerWriteACValueIndex(0, $currSchemeGuid, _GUID_VIDEO_SUBGROUP(), _GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS(), $increment)
Else
$aResult = PowerWriteDCValueIndex(0, $currSchemeGuid, _GUID_VIDEO_SUBGROUP(), _GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS(), $increment)
EndIf
If $aResult = 0 And $PowerApplySettingChanges <> 0 Then ; PowerApplySettingChanges is undocumented and exists only in Windows 8+. Since both the Power control panel and the brightness slider use this, we'll do the same, but fallback to PowerSetActiveScheme if on Windows 7 or something
$aResult = DllCallAddress('UInt', $PowerApplySettingChanges, "Struct*", _GUID_VIDEO_SUBGROUP(), "Struct*", _GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS())
If Not $PowerApplySettingChanges Or $aResult <> 0 Then PowerSetActiveScheme(0, $currSchemeGuid)
EndIf
EndIf
If ($showOSD) Then _ShowBrightnessOSD()
EndIf
_WinAPI_LocalFree($currSchemeGuid)
EndIf
EndFunc ;==>SetBrightness
Func IsOnAc(ByRef $acStatus)
Local $tSYSTEM_POWER_STATUS
If GetSystemPowerStatus($tSYSTEM_POWER_STATUS) Then
$acStatus = $tSYSTEM_POWER_STATUS.ACLineStatus
Return True
EndIf
Return False
EndFunc ;==>IsOnAc
Func GetDefaultBrightnessIncrement()
Static $Ret = 10
PowerReadValueIncrement(Null, _GUID_VIDEO_SUBGROUP(), _GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS(), $Ret)
Return $Ret
EndFunc ;==>GetDefaultBrightnessIncrement
Func GetMinBrightness()
Static $Ret = -1
If $Ret = -1 Then
If (PowerReadValueMin(Null, _GUID_VIDEO_SUBGROUP(), _GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS(), $Ret)) Then $Ret = 0
EndIf
Return $Ret
EndFunc ;==>GetMinBrightness
Func GetMaxBrightness()
Static $Ret = -1
If $Ret = -1 Then
If PowerReadValueMax(Null, _GUID_VIDEO_SUBGROUP(), _GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS(), $Ret) Then $Ret = 100
EndIf
Return $Ret
EndFunc ;==>GetMaxBrightness
Func _GetCurrentBrightness($SchemeGuid, $AC, ByRef $currBrightness)
Local $Ret
If $AC Then
$Ret = PowerReadACValueIndex(0, $SchemeGuid, _GUID_VIDEO_SUBGROUP(), _GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS(), $currBrightness)
Else
$Ret = PowerReadDCValueIndex(0, $SchemeGuid, _GUID_VIDEO_SUBGROUP(), _GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS(), $currBrightness)
EndIf
Return $Ret
EndFunc ;==>_GetCurrentBrightness
Func _ShowBrightnessOSD()
;~ Global $HSHELL_MONITORCHANGED = 16
;~ Global $HSHELL_HIGHBIT = 0x8000
Static $WM_SHELLHOOK = _WinAPI_RegisterWindowMessage('SHELLHOOK')
If @OSVersion = 'WIN_VISTA' Or @OSVersion = 'WIN_7' Then Return
_RealiseOSDWindowIfNeeded() ; Thanks to YashMaster @ https://github.com/YashMaster/Tweaky/blob/master/Tweaky/BrightnessHandler.h for realising this could be done:
If $_osdHwnd Then _WinAPI_PostMessage($_osdHwnd, $WM_SHELLHOOK, 0x37, 0)
EndFunc ;==>_ShowBrightnessOSD
Func _RealiseOSDWindowIfNeeded() ;//此处调用的com接口没查到是什么东西,只能猜着构造一个类型结构。
Local $shellProvider, $flyoutDisp
If (Not _WinAPI_IsWindow($_osdHwnd) And Not _FindAndSetOSDWindow()) Then
$_osdHwnd = 0
$shellProvider = ObjCreateInterface("{C2F03A33-21F5-47FA-B4BB-156362A2F239}", "{00000000-0000-0000-C000-000000000046}")
If IsObj($shellProvider) Then
Local $pObj = Ptr(0)
$shellProvider.QueryInterface("{41f9d2fb-7834-4ab6-8b1b-73e74064b465}", $pObj)
$flyoutDisp = ObjCreateInterface($pObj, "{41f9d2fb-7834-4ab6-8b1b-73e74064b465}", "WhatFuncName1 int();WhatFuncName2 int();WhatFuncName3 int();flyoutDisp UInt(Ptr;INT;UInt);")
$flyoutDisp.flyoutDisp($flyoutDisp.WhatFuncName1, 0, 0)
$flyoutDisp = Null
EndIf
$shellProvider = Null
If _FindAndSetOSDWindow() Then Return
EndIf
; who knows if the SID & IID above will work for future versions of Windows 10 (or Windows 8). Fall back to this if needs must
;~ Loop 2 {
;~ SendEvent {Volume_Mute 2}
;~ if (BrightnessSetter._FindAndSetOSDWindow())
;~ return
;~ Sleep 100
;~ }
;~ EndIf
EndFunc ;==>_RealiseOSDWindowIfNeeded
Func _FindAndSetOSDWindow()
$_osdHwnd = _WinAPI_FindWindow('NativeHWNDHost', '')
Return Not (Not $_osdHwnd)
EndFunc ;==>_FindAndSetOSDWindow
;=========================================================================================
Func PowerGetActiveScheme($UserRootPowerKey, ByRef $ActivePolicyGuid)
$ActivePolicyGuid = DllStructCreate($tagGUID) ;
Local $Ret = DllCall('powrprof.dll', 'DWORD', 'PowerGetActiveScheme', 'PTR', $UserRootPowerKey, 'Struct*', $ActivePolicyGuid)
If Not @error Then Return $Ret
EndFunc ;==>PowerGetActiveScheme
Func PowerSetActiveScheme($UserRootPowerKey, $ActivePolicyGuid)
Local $Ret = DllCall('powrprof.dll', 'DWORD', 'PowerSetActiveScheme', 'PTR', Null, 'struct*', $ActivePolicyGuid)
If Not @error Then Return $Ret
EndFunc ;==>PowerSetActiveScheme
Func PowerWriteACValueIndex($UserRootPowerKey, $SchemeGuid, $SubGroupOfPowerSettingsGuid, $PowerSettingGuid, $AcValueIndex)
Local $Ret = DllCall('powrprof.dll', 'DWORD', 'PowerWriteACValueIndex', 'PTR', $UserRootPowerKey, 'struct*', $SchemeGuid, 'struct*', $SubGroupOfPowerSettingsGuid, 'struct*', $PowerSettingGuid, 'DWORD', $AcValueIndex)
If Not @error Then Return $Ret
EndFunc ;==>PowerWriteACValueIndex
Func PowerWriteDCValueIndex($UserRootPowerKey, $SchemeGuid, $SubGroupOfPowerSettingsGuid, $PowerSettingGuid, $DcValueIndex)
Local $Ret = DllCall('powrprof.dll', 'DWORD', 'PowerWriteDCValueIndex', 'PTR', $UserRootPowerKey, 'struct*', $SchemeGuid, 'struct*', $SubGroupOfPowerSettingsGuid, 'struct*', $PowerSettingGuid, 'DWORD', $DcValueIndex)
If Not @error Then Return $Ret
EndFunc ;==>PowerWriteDCValueIndex
Func PowerDuplicateScheme($RootPowerKey, $SourceSchemeGuid, $DestinationSchemeGuid)
Local $Ret = DllCall('powrprof.dll', 'DWORD', 'PowerDuplicateScheme', 'PTR', $RootPowerKey, 'struct*', $SourceSchemeGuid, 'struct*', $DestinationSchemeGuid)
If Not @error Then Return $Ret
EndFunc ;==>PowerDuplicateScheme
Func PowerReadValueIncrement($RootPowerKey, $SubGroupOfPowerSettingsGuid, $PowerSettingGuid, ByRef $ValueIncrement)
Local $Ret = DllCall('powrprof.dll', 'DWORD', 'PowerReadValueIncrement', 'PTR', $RootPowerKey, 'struct*', $SubGroupOfPowerSettingsGuid, 'struct*', $PowerSettingGuid, 'DWORD*', $ValueIncrement)
$ValueIncrement = $Ret
If Not @error Then Return $Ret
EndFunc ;==>PowerReadValueIncrement
Func PowerReadACValueIndex($RootPowerKey, $SchemeGuid, $SubGroupOfPowerSettingsGuid, $PowerSettingGuid, ByRef $AcValueIndex)
Local $Ret = DllCall('powrprof.dll', 'DWORD', 'PowerReadACValueIndex', 'PTR', $RootPowerKey, 'struct*', $SchemeGuid, 'struct*', $SubGroupOfPowerSettingsGuid, 'struct*', $PowerSettingGuid, 'DWORD*', $AcValueIndex)
$AcValueIndex = $Ret
If Not @error Then Return $Ret
EndFunc ;==>PowerReadACValueIndex
Func PowerReadDCValueIndex($RootPowerKey, $SchemeGuid, $SubGroupOfPowerSettingsGuid, $PowerSettingGuid, ByRef $DcValueIndex)
Local $Ret = DllCall('powrprof.dll', 'DWORD', 'PowerReadDCValueIndex', 'PTR', $RootPowerKey, 'struct*', $SchemeGuid, 'struct*', $SubGroupOfPowerSettingsGuid, 'struct*', $PowerSettingGuid, 'DWORD*', $DcValueIndex)
$DcValueIndex = $Ret
If Not @error Then Return $Ret
EndFunc ;==>PowerReadDCValueIndex
Func PowerReadValueMax($RootPowerKey, $SubGroupOfPowerSettingsGuid, $PowerSettingGuid, ByRef $ValueMaximum)
Local $Ret = DllCall('powrprof.dll', 'DWORD', 'PowerReadValueMax', 'PTR', $RootPowerKey, 'ptr', DllCallbackGetPtr($SubGroupOfPowerSettingsGuid), 'ptr', DllCallbackGetPtr($PowerSettingGuid), 'DWORD*', $ValueMaximum)
$ValueMaximum = $Ret
If Not @error Then Return $Ret
EndFunc ;==>PowerReadValueMax
Func PowerReadValueMin($RootPowerKey, $SubGroupOfPowerSettingsGuid, $PowerSettingGuid, $ValueMinimum)
Local $Ret = DllCall('powrprof.dll', 'DWORD', 'PowerReadValueMin', 'PTR', $RootPowerKey, 'struct*', $SubGroupOfPowerSettingsGuid, 'struct*', $PowerSettingGuid, 'DWORD*', $ValueMinimum)
If Not @error Then Return $Ret
EndFunc ;==>PowerReadValueMin
Func GetSystemPowerStatus(ByRef $SystemPowerStatus)
Local $SYSTEM_POWER_STATUS = 'BYTE ACLineStatus;BYTE BatteryFlag;BYTE BatteryLifePercent;BYTE SystemStatusFlag;DWORD BatteryLifeTime;DWORD BatteryFullLifeTime'
$SystemPowerStatus = DllStructCreate($SYSTEM_POWER_STATUS)
Local $aRet = DllCall('kernel32.dll', 'BOOL', 'GetSystemPowerStatus', 'Struct*', $SystemPowerStatus)
If Not @error Then Return $aRet
EndFunc ;==>GetSystemPowerStatus
AHK支持类啊,看来au3发展确实太慢了。。。
这么长的代码,你赞助一下论坛,我给你翻译一下~ 本帖最后由 sanmaodo 于 2019-7-21 01:35 编辑
haijie1223 发表于 2019-7-8 13:48
AHK支持类啊,看来au3发展确实太慢了。。。
这么长的代码,你赞助一下论坛,我给你翻译一下~
谢谢!已赞助
sanmaodo 发表于 2019-7-21 01:31
谢谢!已赞助
谢谢!这个脚本是完整的吗,我运行后没有效果呢。 haijie1223 发表于 2019-7-21 09:29
谢谢!这个脚本是完整的吗,我运行后没有效果呢。
明天测试一下,再发上来,谢谢老大了! 不错支持一下
页:
[1]