首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将Autoit转换为Python

将Autoit转换为Python
EN

Stack Overflow用户
提问于 2012-04-01 04:54:23
回答 1查看 3.5K关注 0票数 0

我有一个很棒的小AutoIt脚本,我在过去的几年里一直在使用它。它最初是为Skype构建的,用于将占用RAM的应用程序的内存使用量减少到他们需要的最低限度(仅适用于Windows ),并将其保持在尽可能低的水平,只给他们真正需要的东西。它看起来是这样的:

代码语言:javascript
复制
#include <Misc.au3>
_Singleton("skype-memory-reducer")

Opt("TrayMenuMode", 1)
Opt("TrayOnEventMode", 1)

TrayCreateItem("Quit")
TrayItemSetOnEvent(-1, "Bye")
TraySetState()

Global Const $interval = 2000 ; interval at which the memory is freed, anything below this will almost certainly only slow down your system.

;here you can add any other process,
;but be carefull which process you choose,
;bacause in some cases this will slow down your application or even your PC
Global $list = "skype.exe|skypePM.exe"
Global $processlist = StringSplit($list, "|")

While 1
    For $i = 1 To UBound($processlist) - 1
        $pid = ProcessExists($processlist[$i])
        If $pid Then _ReduceMemory($pid)
    Next
    _ReduceMemory(); also reduce the memory used by the script itself...
    Sleep($interval)
WEnd

Func Bye()
    Exit
EndFunc   ;==>Bye

;I don't remember who was the author of this UDF... (it's not me)
Func _ReduceMemory($i_PID = -1)
    If $i_PID <> -1 Then
        Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
        DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
    Else
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
    EndIf

    Return $ai_Return[0]
EndFunc   ;==>_ReduceMemory 

现在,我正在寻找尝试完成相同的事情,但严格地使用Python。要么是通过Python中完全原生的东西,要么是可以在Python中运行Autoit脚本而不需要调用另一个进程的东西。

感谢您的帮助,谢谢!

编辑:以防万一,我希望我的应用程序最终是可移植的。因此,我尽量避免在Windows中注册任何DLL(以防有人考虑使用Win32模块),再次谢谢!

EN

回答 1

Stack Overflow用户

发布于 2012-04-01 05:48:05

您可以使用ctypes模块来访问Windows DLL。这将允许您重写_ReduceMemory函数。程序的其余部分似乎相当微不足道。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9959618

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档