urlencode(string,encoding:="UTF-8"){ VarSetCapacity(pstr,ceil(strlen(string)*1.5+10),0) StrPut(string,&pstr,,encoding) int := "1" while (int){ int := ToBase(NumGet(&pstr,(A_index-1)*4,"Uint"),16) RegExMatch(int,"(.{2})(.{2})(.{2})(.{2})",m) loop 4 { i := 4-A_index+1 hex := % m%i% if hex { hex2 := "0x" hex If (hex2==33 || (hex2>=39 && hex2 <=42) || hex2==45 || hex2 ==46 || (hex2>=48 && hex2<=57) || (hex2>=65 && hex2<=90) || hex2==95 || (hex2>=97 && hex2<=122) || hex2==126) out .= chr("0x" hex) else out .= "%" hex } } } Return out } ToBase(n,b){ return (n < b ? "" : ToBase(n//b,b)) . ((d:=Mod(n,b)) < 10 ? d : Chr(d+55)) }
#NoTrayIcon ;不显示图标 stdin := FileOpen("*", "r") ;使用stdin,文件对象 content := stdin.read() ;读取 Clipboard := RegExReplace(content,"\r*\n*$","") ;输出到剪切板
编译成exe放在c:\windows\就可以了。也适用于其他windows系统或者改造来获取cmd管道数据,例如:
cmd.exe /c ping 114.114.114.114 |clip.exe
下载成品clip.zip
msgbox % ToBase(0xFF,10) ;Hex->Dec msgbox % ToBase(0xFF,8) ;Hex->Oct ToBase(n,b){ return (n < b ? "" : ToBase(n//b,b)) . ((d:=Mod(n,b)) < 10 ? d : Chr(d+55)) }
by Tmplinshi
UrlUpLevel(url) { url := Trim(url, " `t`r`n/\") url := !(url ~= "\w/\w") ? RegExReplace(url, "\w+\.(?=.*\.)",,, 1) : RegExReplace(url, "\w\K/[^/]+$") url := (url ~= "i)^(ftp|https?)://") ? url : "http://" url Return url }
OnMessage(0x404,"TB_HIDEBUTTON") Traytip, 提示, 点击测试, 10, 1 return TB_HIDEBUTTON(wParam, lParam, msg, hwnd) { static WM_USER := 0x400 static _______ := OnMessage(WM_USER + 4, "TB_HIDEBUTTON") If (lParam = 1029) { MsgBox TrayTip Click`, AutoHotkey will now exit ExitApp } }
#NoEnv #SingleInstance myUdpOut := new udp() ;新的udp对象 ;Erstelle ein neues udp-Objekt 'myUdpOut' myUdpOut.connect("192.168.8.7", 8000) ;对方IP和端口 ;client ip and port hex_str := "ef010100ffffffffffff0100800100009c95" ;十六进制流 length := StrLen(hex_str)/2 ;多少字节 VarSetCapacity(buff,length,0) ;申请内存 loop % length { NumPut("0x" SubStr(hex_str,A_index*2-1,2), &buff, A_index-1, "UChar") ;按字节写入十六进制到内存 } myUdpOut.sendBinary(&buff, length) ;发送二进制数据 myUdpOut.disconnect() ExitApp return ;; ------------------------------------------------- ;; with thanks to Bentschi for udp class class udp { __New() { __nw_initWinsock() this.__protocolId := 17 ;IPPROTO_UDP this.__socketType := 2 ;SOCK_DGRAM this.socket := -1 } __Delete() { this.disconnect() } bind(host, port) { if ((this.socket!=-1) || (!(next := __nw_getaddrinfo(host, port)))) return 0 while (next) { sockaddrlen := NumGet(next+0, 16, "uint") sockaddr := NumGet(next+0, 16+(2*A_PtrSize), "ptr") if ((this.socket := DllCall("ws2_32\socket", "int", NumGet(next+0, 4, "int"), "int", this.__socketType, "int", this.__protocolId, "ptr"))!=-1) { if (DllCall("ws2_32\bind", "ptr", this.socket, "ptr", sockaddr, "uint", sockaddrlen, "int")=0) return 1 this.disconnect() } next := NumGet(next+0, 16+(3*A_PtrSize), "ptr") } this.lastError := DllCall("ws2_32\WSAGetLastError") return 0 } connect(host, port) { if ((this.socket!=-1) || (!(next := __nw_getaddrinfo(host, port)))) return 0 while (next) { sockaddrlen := NumGet(next+0, 16, "uint") sockaddr := NumGet(next+0, 16+(2*A_PtrSize), "ptr") if ((this.socket := DllCall("ws2_32\socket", "int", NumGet(next+0, 4, "int"), "int", this.__socketType, "int", this.__protocolId, "ptr"))!=-1) { if ((r := DllCall("ws2_32\WSAConnect", "ptr", this.socket, "ptr", sockaddr, "uint", sockaddrlen, "ptr", 0, "ptr", 0, "ptr", 0, "ptr", 0, "int"))=0) return 1 this.disconnect() } next := NumGet(next+0, 16+(3*A_PtrSize), "ptr") } this.lastError := DllCall("ws2_32\WSAGetLastError") return 0 } disconnect() { DllCall("ws2_32\closesocket", "ptr", this.socket, "int") this.socket := -1 ;INVALID_SOCKET return 1 } enableBroadcast() { VarSetCapacity(optval, 4, 0) NumPut(1, optval, 0, "uint") if (DllCall("ws2_32\setsockopt", "ptr", this.socket, "int", 0xFFFF, "int", 0x0020, Ptr, &optval, "int", 4)=0) return 1 return 0 } disableBroadcast() { VarSetCapacity(optval, 4, 0) if (DllCall("ws2_32\setsockopt", "ptr", this.socket, "int", 0xFFFF, "int", 0x0020, Ptr, &optval, "int", 4)=0) return 1 return 0 } msgSize() { VarSetCapacity(argp, 4, 0) if (DllCall("ws2_32\ioctlsocket", "ptr", this.socket, "uint", 0x4004667F, "ptr", &argp)!=0) return 0 return NumGet(argp, 0, "int") } sendBinary(addr, length) { if ((r := DllCall("ws2_32\send", "ptr", this.socket, "ptr", addr, "int", length, "int", 0, "int"))<=0) return 0 return r } send(msg, encoding="UTF-8") { VarSetCapacity(buffer, length := (StrPut(msg, encoding)*(((encoding="utf-16")||(encoding="cp1200")) ? 2 : 1))) StrPut(msg, &buffer, encoding) return this.sendBinary(&buffer, length) } recvBinary(byref buffer, wait=1) { while ((wait) && ((length := this.msgSize())=0)) sleep, 50 if (length) { VarSetCapacity(buffer, length) if ((r := DllCall("ws2_32\recv", "ptr", this.socket, "ptr", &buffer, "int", length, "int", 0))<=0) return 0 return r } return 0 } recv(wait=1, encoding="UTF-8") { if (length := this.recvBinary(buffer, wait)) return StrGet(&buffer, length, encoding) return } onRecv(callback) { this.__onRecv := callback return __nw_eventProc("register", 1, this, 0) } } __nw_initWinsock() { static init if (!init) { DllCall("LoadLibrary", "str", "ws2_32", "ptr") VarSetCapacity(wsadata, 394+A_PtrSize) DllCall("ws2_32\WSAStartup", "ushort", 0x0000, "ptr", &wsadata) DllCall("ws2_32\WSAStartup", "ushort", NumGet(wsadata, 2, "ushort"), "ptr", &wsadata) init := 1 } } __nw_getAddrInfo(host, port) { if host in localhost,addr_loopback,inaddr_loopback host := "127.0.0.1" else if host in addr_any,inaddr_any host := "0.0.0.0" else if host in addr_broadcast,inaddr_broadcast,addr_none,inaddr_none host := "255.255.255.255" else if host in localhost6,addr_loopback6,inaddr_loopback6 host := "::1" else if host in addr_any6,inaddr_any6 host := "::" else if host in addr_broadcast6,inaddr_broadcast6,addr_none6,inaddr_none6 host := "FF00::" VarSetCapacity(hints, 16+(4*A_PtrSize), 0) NumPut(this.__inetType, hints, 4, "int") NumPut(this.__socketType, hints, 8, "int") NumPut(this.__protocolId, hints, 12, "int") if ((r := DllCall("ws2_32\getaddrinfo", "astr", host, "astr", port, "ptr", &hints, "ptr*", next))!=0) { this.lastError := DllCall("ws2_32\WSAGetLastError") return 0 } return next } __nw_eventProc(wParam, lParam, msg, hwnd) { static if (wParam="register") { if (!init) { OnMessage(0x9987, A_ThisFunc) Gui, +LastFound hMsgWnd := WinExist() array := Object() init := 1 } array.Insert(msg) return (DllCall("ws2_32\WSAAsyncSelect", "ptr", msg.socket, "ptr", hMsgWnd, "uint", 0x9987, "uint", lParam)=0) ? 1 : 0 } found := 0 for i,element in array { if (element.socket = wParam) { this := element found := 1 break } } if (!found) return 0 func := "" if ((lParam & 0xFFFF) = 1) func := this.__OnRecv else if ((lParam & 0xFFFF) = 8) func := this.__OnAccept else if ((lParam & 0xFFFF) = 32) func := this.__OnDisconnect if (IsFunc(func)) return %func%(this) return 0 }
Gui, Add, TreeView P1 := TV_Add("P1") P1C1 := TV_Add("P1C1", P1) P1C1D1 := TV_Add("P1C1D1", P1C1) P1C1D2 := TV_Add("P1C1D2", P1C1) P1C1D3 := TV_Add("P1C1D3", P1C1) P1C1D2E1 := TV_Add("P1C1D2E1", P1C1D2) P1C1D2E2 := TV_Add("P1C1D2E2", P1C1D2) Gui, Show ;获取节点信息 top := TV_GetSelection() ;Clipboard := var_dump(gettvchild(top)) ;展开选中下所有节点 ;TV_Modify(top,"Expand") Clipboard := var_dump(expandallchild(top)) return gettvchild(id){ ret = if(firstid := TV_GetChild(id)){ ret := [],first := true ret[firstid] := "" while(nextid := TV_GetNext(first ? (firstid,first:=false) : nextid)){ ret[nextid] := "" } } for k,v in ret { if (TV_GetChild(k)) ret[k] := gettvchild(k) } return ret } expandallchild(id){ ret := "",TV_Modify(id,"Expand") if(firstid := TV_GetChild(id)){ ret := [],first := true ret[firstid] := "" while(nextid := TV_GetNext(first ? (firstid,first:=false) : nextid)){ ret[nextid] := "" } } for k,v in ret { if (TV_GetChild(k)) TV_Modify(k,"Expand"),ret[k] := expandallchild(k) } return ret } var_dump(obj,level:=0){ static str if !level str := "" if IsObject(obj) { space = loop % level space .= A_Tab str .= space "{`n" for k,v in obj { if IsObject(v) { str .= space A_Tab (RegExMatch(k,"^\d+$") ? k : """" k """") ":`n" var_dump(v,level+1) str := RegExReplace(str,"(*ANYCRLF)\n$",",`n") } else str .= space A_Tab (RegExMatch(k,"^\d+$") ? k : """" k """") ":""" RegExReplace(v,"""","""""") """,`n" } str := RegExReplace(str,"(*ANYCRLF),\n*$","`n") str .= space "}`n" } else str := obj return str } GuiClose: ; 当用户关闭 TreeView 所在的 GUI 窗口时退出脚本. ExitApp
MsgBox % uploadfile("D:\我的文档\My Music\success.mp3","record\success.mp3") uploadfile(src,dst){ IfExist % src { objParam := {"upfile":[src],"dst":dst} ;post数据 CreateFormData(PostData, hdr_ContentType, objParam) whr := ComObjCreate("WinHttp.WinHttpRequest.5.1") whr.Open("POST", "http://135.230.71.1/upload.php", true) ;地址 whr.SetRequestHeader("Content-Type", hdr_ContentType) whr.Send(PostData) whr.WaitForResponse() return whr.ResponseText } } CreateFormData(ByRef retData, ByRef retHeader, objParam) { New CreateFormData(retData, retHeader, objParam) } Class CreateFormData { __New(ByRef retData, ByRef retHeader, objParam) { CRLF := "`r`n" ; Create a random Boundary Boundary := this.RandomBoundary() BoundaryLine := "------------------------------" . Boundary ; Loop input paramters binArrs := [] For k, v in objParam { If IsObject(v) { For i, FileName in v { str := BoundaryLine . CRLF . "Content-Disposition: form-data; name=""" . k . """; filename=""" . FileName . """" . CRLF . "Content-Type: " . this.MimeType(FileName) . CRLF . CRLF binArrs.Push( BinArr_FromString(str) ) binArrs.Push( BinArr_FromFile(FileName) ) binArrs.Push( BinArr_FromString(CRLF) ) } } Else { str := BoundaryLine . CRLF . "Content-Disposition: form-data; name=""" . k """" . CRLF . CRLF . v . CRLF binArrs.Push( BinArr_FromString(str) ) } } str := BoundaryLine . "--" . CRLF binArrs.Push( BinArr_FromString(str) ) ; Finish retData := BinArr_Join(binArrs*) retHeader := "multipart/form-data; boundary=----------------------------" . Boundary } RandomBoundary() { str := "0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z" Sort, str, D| Random str := StrReplace(str, "|") Return SubStr(str, 1, 12) } MimeType(FileName) { n := FileOpen(FileName, "r").ReadUInt() Return (n = 0x474E5089) ? "image/png" : (n = 0x38464947) ? "image/gif" : (n&0xFFFF = 0x4D42 ) ? "image/bmp" : (n&0xFFFF = 0xD8FF ) ? "image/jpeg" : (n&0xFFFF = 0x4949 ) ? "image/tiff" : (n&0xFFFF = 0x4D4D ) ? "image/tiff" : "application/octet-stream" } } BinArr_FromString(str) { oADO := ComObjCreate("ADODB.Stream") oADO.Type := 2 ; adTypeText oADO.Mode := 3 ; adModeReadWrite oADO.Open oADO.Charset := "UTF-8" oADO.WriteText(str) oADO.Position := 0 oADO.Type := 1 ; adTypeBinary oADO.Position := 3 ; Skip UTF-8 BOM return oADO.Read, oADO.Close } BinArr_FromFile(FileName) { oADO := ComObjCreate("ADODB.Stream") oADO.Type := 1 ; adTypeBinary oADO.Open oADO.LoadFromFile(FileName) return oADO.Read, oADO.Close } BinArr_Join(Arrays*) { oADO := ComObjCreate("ADODB.Stream") oADO.Type := 1 ; adTypeBinary oADO.Mode := 3 ; adModeReadWrite oADO.Open For i, arr in Arrays oADO.Write(arr) oADO.Position := 0 return oADO.Read, oADO.Close } BinArr_ToString(BinArr, Encoding := "UTF-8") { oADO := ComObjCreate("ADODB.Stream") oADO.Type := 1 ; adTypeBinary oADO.Mode := 3 ; adModeReadWrite oADO.Open oADO.Write(BinArr) oADO.Position := 0 oADO.Type := 2 ; adTypeText oADO.Charset := Encoding return oADO.ReadText, oADO.Close } BinArr_ToFile(BinArr, FileName) { oADO := ComObjCreate("ADODB.Stream") oADO.Type := 1 ; adTypeBinary oADO.Open oADO.Write(BinArr) oADO.SaveToFile(FileName, 2) oADO.Close }
conv2num(str){ d := {"零":0,"一":1,"二":2,"两":2,"三":3,"四":4,"五":5,"六":6,"七":7,"八":8,"九":9,"十":10,"百":100,"千":1000,"万":10000,"亿":100000000} n = 0 a := StrSplit(str,"亿") if a[2] { b := StrSplit(a[2],"万") s1 := a[1],s2 := b[1], s3 := b[2] } else { a := StrSplit(str,"万") s1 := a[1],s2 := a[2], s3 := "" } l1 := InStr(str,"亿") ? d["亿"] : (InStr(str,"万") ? d["万"] : 1) l2 := InStr(a[2],"万") ? d["万"] : (a[2] ? 1 : 0) l3 := b[2] ? 1 : 0 if l1=1 { Loop { if !str break if RegExMatch(str,"^(一|二|两|三|四|五|六|七|八|九)(十|百|千|)(.*)",m) { t := d[m1] * (m2 ? d[m2] : 1) n += t, str := m3 } else if RegExMatch(str,"^十(一|二|两|三|四|五|六|七|八|九|)$",m) { t := 10 + (m1 ? d[m1] : 0) n += t, str := "" } else if RegExMatch(str,"^零(.*)",m) str := m1 } } else n := conv2num(s1)*l1 + conv2num(s2)*l2 + conv2num(s3)*l3 return n }
runlink(linkfile){ FileGetShortcut, % linkfile, OutTarget, OutDir, OutArgs SetWorkingDir % OutDir Run, % """" OutTarget """" (OutArgs ? " """ OutArgs """" : "") SetWorkingDir % A_ScriptDir }
50 queries in 1.198 seconds |