Skip to content

Instantly share code, notes, and snippets.

@TLMcode
TLMcode / ExecScript.ahk
Last active December 18, 2018 18:54
Execute an script
ExecScript( Script, Params="", AhkPath="" )
{
AhkPath := !AhkPath ? A_AhkPath : AhkPath
Loop % ( 2, Pipe := [], Name := "AHK_" A_TickCount )
Pipe[A_Index] := DllCall( "CreateNamedPipe", "Str", "\\.\pipe\" name, "UInt", 2, "UInt", 0
, "UInt", 255, "UInt", 0, "UInt", 0, "UPtr", 0, "UPtr", 0, "UPtr" )
if !FileExist( AhkPath )
throw Exception( "AutoHotkey runtime not found: " AhkPath )
@TLMcode
TLMcode / Random String Generator
Last active January 23, 2017 23:08
Random String Generator
gen( len )
{
loop % (122, d="~")
cStr .= chr( (i:=a_index)>32&&i<60 ? i : i>59&&i<91 ? i : i>93&&i<125 ? i : "" ) d
cStr:=regexreplace(cStr, d d)
while ( strlen(nStr)<len )
{
sort, cStr, % "Random D" d
nStr .= ((v:=substr(regexreplace(cStr,d),1,20))~="\d"
@TLMcode
TLMcode / ShortGitURL.ahk
Last active March 1, 2016 03:19
ShortGitURL() shorten GitHub url's using git.io in AutoHotkey
msgbox % ShortGitURL( "https://github.com/blog/category/ship" ) ; example long git url
ShortGitURL( gitURL )
{
hReq := ComObjCreate("Microsoft.XMLHTTP")
hReq.Open("GET", "https://git.io", False), hReq.Send("url=" gitURL)
Return hReq.getResponseHeader("Location")
}
@TLMcode
TLMcode / TileWindows()
Last active March 19, 2016 19:04
TileWindows()
; API call https://msdn.microsoft.com/en-us/library/windows/desktop/ms633554(v=vs.85).aspx
Window_Tile(Monitor=""){
; Required constants: MDITILE_VERTICAL
; SM_CMONITORS
; WS_CAPTION
; WS_MAXIMIZEBOX
; WS_MINIMIZE
; WS_VISIBLE
; WS_EX_TOOLWINDOW
wHow:=MDITILE_VERTICAL
@TLMcode
TLMcode / eval.ahk
Last active March 24, 2016 01:01
Single line maths Eval() function using a HTMLFile object and COM for ahk http://p.ahkscript.org/?p=f33c5102 🤓👍✨ (debugged)
msgbox % eval("2*4*23") " <> " (2*4*23) "`n" eval("Math.pow(3,7)") " <> " (3**7) "`n" eval( "5*9*poo" )
eval( exp )
{
return InStr([(o:=ComObjCreate("HTMLfile")).Write(".<script>document.body.innerHTML=eval('" exp "')</script>"),r:=o.body.innerHTML][2],"<")?"Error":r
}
@TLMcode
TLMcode / RunChrome.ahk
Created April 1, 2016 11:18
RunChrome() waits for page to load then moves the chrome window to the coordinate array.
new RunChrome( "https://autohotkey.com", [ 0, 0, 1000, 500 ] )
return
Esc::ExitApp
class RunChrome
{
__New( url, coords )
{
this.arr := this.EnumWindows(), this.ShellHookWindow( 1 )
@TLMcode
TLMcode / GetSamples.ahk
Created April 7, 2016 10:40
GetSamples() ; delta-time to samples converter
GetSamples( bin, ppq, tmpo, srate = 44.1, debug = 0 )
{
; credit: just me >> https://autohotkey.com/boards/viewtopic.php?f=5&t=15637
Loop
r := ( (!r?r!!:r) << 7 ) + ( ( h := "0x" . SubStr( bin, ( a_index * 2) - 1, 2 ) ) & 0x7F )
Until ( h <= 0x80 )
Return debug ? r : Round( r * ( 60000 / ( ( 60000000 / tmpo ) * ppq ) ) * srate )
}
@TLMcode
TLMcode / WatchWindow.ahk
Created April 21, 2016 14:26
Pseudo Watch Window Event Handler. Embeds an instructional AHk GUI into a parent window using Win32 API SetParent() function.
SetTimer, WatchWindow, 100
xOfs := 189, yOfs := 30, GuiCnt := 0
WatchWindow:
ControlGet, PlgHwnd, Hwnd,, eXTVSTiwin1, ahk_class TPluginForm
if ( WinExist( "ahk_id " PlgHwnd ) && GuiCnt = 0 )
{
Gui Font, s7 CA0E6E6
@TLMcode
TLMcode / Rand()
Created April 23, 2016 22:33
Rand() wrapper for AHk
rand( min = 0, max = 10000 ) {
random, rand, % min, % max
return rand
}
@TLMcode
TLMcode / ClickCoords().ahk
Created April 26, 2016 07:42
ClickCoords() full click sequence
ClickCoords( x, y, wT, ctrl = "", btn := "left" )
{
For Each, Msg in ( btn = "left" ? ( l := [ 1, 0, 2 ] ) : btn = "right" ? [ 4, 0, 5 ] : l )
PostMessage, % 0x20 Msg, 0x1, % x|y<<16, % ctrl, % wT
}