Quickly share code / Text with AHK Pastbin

I’m working my way through my main AutoHotkey.ahk file and thought I’d share this gem which helps sharing code / text with people.

I borrowed the “guts” of it from an AHK Studio plugin.  I’m also using Maestrith’s Notify Class / Function.

Quickly share code / Text with AHK Pastbin

https://youtu.be/Dgi44702l2E

Here’s the code (but make sure you get the above mentioned Notify Class/Function.

Quickly share code / Text with AHK Pastbin


Browser_Back:: ;Select, copy, paste selected text to AutoHotkey Pastebin
clipboard:="" ;Blank out clipboard
Send, ^c ;Send Copy
ClipWait, 1 ;wait for clipboard to be populated
Clipboard:=AHKPastebin(Clipboard,"Joe Glines",1,0) ;1 will run it in your default browser, 0 doesn't
return

AHKPastebin(Content,Name:="",Notify:=1,Run:=0){
HTTP:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
HTTP.Open("POST","https://p.ahkscript.org/", False)
HTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
HTTP.Send("code=" UriEncode(Content) "&name=" UriEncode(Name) "&channel=#ahkscript")
if HTTP.Status()!=200{ ;If not okay
MsgBox Something went wrong
return
}
If (Notify)
Notify().AddWindow(Content,{Time:3000,Icon:300,Background:"0x1100AA",Icon:14,Title:"Added to pastebin at: " HTTP.Option(1),TitleSize:18,size:14,TitleColor:"0xFF0000"})
If (Run)
Run % HTTP.Option(1) ;URL
return HTTP.Option(1) ;Return URL
}

;~ ;********************URI Encode string***********************************
UriEncode(Uri, RE="[0-9A-Za-z]"){
VarSetCapacity(Var,StrPut(Uri,"UTF-8"),0),StrPut(Uri,&Var,"UTF-8")
While Code:=NumGet(Var,A_Index-1,"UChar")
Res.=(Chr:=Chr(Code))~=RE?Chr:Format("%{:02X}",Code)
Return,Res
}

AHK Studio is an impressive IDE / editor for AutoHotkey

AHK Studio is an amazing and impressive IDE / Editor for AutoHotkey

AHK Studio editor for AutoHotkeyI had an in-depth Hangout with Chad Wilson (Maestrith on the forum), the Author and Designer of AHK Studio.   Check out my AHK Studio tutorials here

While I’ve been, and still am, a very satisfied SciTE4AHK user, I was very impressed with many aspects of the tool.  It is very intuitive to use and offers some great features that will simplify a coding.  Not surprisingly AHK Studio is loaded with HotKeys that, once you familiarize yourself with them, will be awesome!  While advanced programmers in AutoHotkey will love the advanced functionality, Noobs will enjoy it’s simplicity.

Here are links where you can you can download it from the AHK forum or from GitHub.  Please keep in mind it is still in development.  (This is both good and bad.  It is good because Chad is very active and open to tweaks/fixes/improvements, bad because “kinks” are never fun)

AHK Studio

Here are a few videos on AHK Studio  and below is the nearly 2-hour video demonstrating some of the configuration settings and functionality.

Setup & Review of AHK Studio- Great IDE & editor for AutoHotkey