• Become a Power user Intro to AutoHotkey Intermediate AutoHotkey Intermediate Objects GUIs are Easy w/AutoHotkey Painlessly switch from V1 to V2

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

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

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
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]"){
While Code:=NumGet(Var,A_Index-1,"UChar")