Skip to content

Instantly share code, notes, and snippets.

@sidola
sidola / DownloadToString.ahk
Created May 3, 2014 17:10
AHK - Download HTML data to a variable
DownloadToString(url, encoding = "utf-8")
{
static a := "AutoHotkey/" A_AhkVersion
if (!DllCall("LoadLibrary", "str", "wininet") || !(h := DllCall("wininet\InternetOpen", "str", a, "uint", 1, "ptr", 0, "ptr", 0, "uint", 0, "ptr")))
return 0
c := s := 0, o := ""
if (f := DllCall("wininet\InternetOpenUrl", "ptr", h, "str", url, "ptr", 0, "uint", 0, "uint", 0x80003000, "ptr", 0, "ptr"))
{
while (DllCall("wininet\InternetQueryDataAvailable", "ptr", f, "uint*", s, "uint", 0, "ptr", 0) && s > 0)
{
@sidola
sidola / DownloadToFile.ahk
Created May 3, 2014 17:11
AHK - Download HTML data to a file
DownloadToFile(url, filename)
{
static a := "AutoHotkey/" A_AhkVersion
if (!(o := FileOpen(filename, "w")) || !DllCall("LoadLibrary", "str", "wininet") || !(h := DllCall("wininet\InternetOpen", "str", a, "uint", 1, "ptr", 0, "ptr", 0, "uint", 0, "ptr")))
return 0
c := s := 0
if (f := DllCall("wininet\InternetOpenUrl", "ptr", h, "str", url, "ptr", 0, "uint", 0, "uint", 0x80003000, "ptr", 0, "ptr"))
{
while (DllCall("wininet\InternetQueryDataAvailable", "ptr", f, "uint*", s, "uint", 0, "ptr", 0) && s > 0)
{
@sidola
sidola / DownloadBin.ahk
Created May 3, 2014 17:11
AHK - Download HTML data to binary
DownloadBin(url, byref buf)
{
static a := "AutoHotkey/" A_AhkVersion
if (!DllCall("LoadLibrary", "str", "wininet") || !(h := DllCall("wininet\InternetOpen", "str", a, "uint", 1, "ptr", 0, "ptr", 0, "uint", 0, "ptr")))
return 0
c := s := 0
if (f := DllCall("wininet\InternetOpenUrl", "ptr", h, "str", url, "ptr", 0, "uint", 0, "uint", 0x80003000, "ptr", 0, "ptr"))
{
while (DllCall("wininet\InternetQueryDataAvailable", "ptr", f, "uint*", s, "uint", 0, "ptr", 0) && s > 0)
{
@sidola
sidola / CPULoad.ahk
Created May 4, 2014 07:26
AHK - Get the current CPU load
CPULoad() { ; By SKAN / 22-Apr-2014. Thanks to ejor, Codeproject: http://goo.gl/epYnkO
Static GetSystemTimes, PIT, PKT, PUT ; Note > vars Pxx is Previous and Cxx is Current
If ! GetSystemTimes
GetSystemTimes := DllCall( "GetProcAddress", UInt, DllCall( "GetModuleHandle"
, Str,"Kernel32.dll" ), A_IsUnicode ? "AStr" : "Str","GetSystemTimes" )
, DllCall( GetSystemTimes, Int64P,PIT, Int64P,PKT, Int64P,PUT )
DllCall( GetSystemTimes, Int64P,CIT, Int64P,CKT, Int64P,CUT )
, IdleTime := PIT - CIT, KernelTime := PKT - CKT, UserTime := PUT - CUT
, SystemTime := KernelTime + UserTime
@sidola
sidola / PostClick.ahk
Created June 6, 2014 08:20
AHK - Send click to hidden window
PostClick(x, y, class, title)
{
lParam := x & 0xFFFF | (y & 0xFFFF) << 16
PostMessage, 0x201, 1, %lParam%, %class%, %title% ;WM_LBUTTONDOWN
PostMessage, 0x202, 0, %lParam%, %class%, %title% ;WM_LBUTTONUP
}
@sidola
sidola / AutoSort.ahk
Created June 24, 2014 09:04
AHK - Sort an array
AutoSort(Arr) {
t := []
for k, v in Arr
t[RegExReplace(v, "\s")] := v
for k, v in t
Arr[A_Index] := v
return Arr
}
@sidola
sidola / PIDfromAnyID
Created June 24, 2014 09:13
AHK - Gets the PID from any ID
PIDfromAnyID( anyID="" ) { ; SKAN, 10-May-2014. http://ahkscript.org/boards/viewtopic.php?p=17974#p17974
Process, Exist, %anyID%
IfGreater, ErrorLevel, 0, Return ErrorLevel
DetectHiddenWindows, % SubStr( ( ADHW := A_DetectHiddenWindows ) . "On", -1 )
SetTitleMatchMode, % SubStr( ( ATMM := A_TitleMatchMode ) . "RegEx", -4 )
WinGet, PID, PID, ahk_id %anyID%
IfEqual, PID,, WinGet, PID, PID, %anyID%
DetectHiddenWindows, %ADHW%
SetTitleMatchMode, %ATMM%
Return PID ? PID : 0
@sidola
sidola / ControlPanelItem()
Created July 3, 2014 07:52
AHK - Create a controlpanel shortcut
F1::ComObjCreate("shell.application").ControlPanelItem("Firewall.cpl")
@sidola
sidola / SetParentByTitle
Last active August 29, 2015 14:04
AHK - Sets a GUI as a child to a parent, via parent window-name
SetParentByTitle(Window_Title_Text, Gui_Number) ; F
{
WinGetTitle, Window_Title_Text_Complete, %Window_Title_Text%
Parent_Handle := DllCall( "FindWindowEx", "uint",0, "uint",0, "uint",0, "str", Window_Title_Text_Complete)
Gui, %Gui_Number%: +LastFound
Return DllCall( "SetParent", "uint", WinExist(), "uint", Parent_Handle )
}
@sidola
sidola / SetParentByClass
Last active August 29, 2015 14:04
AHK - Sets a GUI as a child to a parent, via parent class
SetParentByClass(Window_Class, Gui_Number) ; F
{
Parent_Handle := DllCall( "FindWindowEx", "uint",0, "uint",0, "str", Window_Class, "uint",0)
Gui, %Gui_Number%: +LastFound
Return DllCall( "SetParent", "uint", WinExist(), "uint", Parent_Handle )
}