剪贴板类库(WinClip)是由Deo积累编写的,主要作用是拓展ahk原有的剪贴板函数,支持rtf、html和图片等格式。本类库的翻译工作将会陆续开展,考虑到大家访问国外网站可能会缓慢,我就直接把官网那边的帮助复制过来了。
类库的下载链接:http://www.apathysoftworks.com/ahk/WinClip.zip
下边是函数列表:
函数 | 描述 |
---|---|
Snap( ByRef data ) | Copies current data from Windows clipboard(拷贝剪贴板当前的数据) data – variable where the data will be copied(数据-要被拷贝的数据) returns number of bytes copied from clipboard(返回剪贴板拷贝的字节的数量) |
iSnap() | Same as above, but puts data to the inner buffer(同上,但是把数据放在内部缓存中) |
Restore( ByRefdata ) | Puts clip data got earlier through Snap() method back to Windows clipboard(将剪贴数据通过Snap()方法放回系统剪贴板) data – variable containing clipboard data which will be placed on Windows clipboard(数据——将被放回系统剪贴板的数据变量) returns number of bytes writen to clipboard(返回写入剪贴板数据的字节数) |
iRestore() | Same as above, but gets data from inner buffer saved earlier through iSnap()(同上,只是从内部缓存获取数据通过iSnap()方法) |
Clear() | Clears current Windows clipboard, e.g. removes all data from it(清除系统剪贴板数据) |
iClear() | Clears inner clipboard buffer, does not touch Windows clipboard in any way(清空内部剪贴板缓存,不影响系统剪贴板) |
GetFormats() | Returns list of all formats Windows clipboard currently has in form of array: see below for example |
iGetFormats() | Same as above, but parses currently kept inner buffer of clipboard data |
Save( filePath ) | Saves current clipboard data into file filePath – path to file returns number of bytes writen |
iSave( filePath ) | Same as above, but saves data from inner buffer |
Load( filePath ) | Loads data from file directly to Windows clipboard filePath – path to file returns number of bytes read |
iLoad( filePath ) | Same as above, but loads data into inner buffer |
Copy() | Clear current Windows clipboard, then send ctrl+c to the active window |
iCopy() | Same as above, but copies new data into inner buffer without changing current Win clipboard content |
Paste( plainText = “” ) | Just sends ctrl+v into active window plainText – if presented and not blank, it’s content will be pasted instead, without changing original clipboard data |
iPaste() | Copies clip data from inner buffer to clipboard and sends ctrl+v to active window |
GetFiles() | Returns list of files Windows clipboard has for copying delimited with `n. This function will return anything only if you previously copied some files from explorer window |
iGetFiles() | Same as above regarding inner clipboard buffer |
SetFiles( files, isCut = 0 ) | Sets the list of files on clipboard which can be used in paste operations later through explorer windows files – “`n” delimited list of files isCut – if 1, on paste files will be cutted from original place |
iSetFiles( files, isCut = 0 ) | Same as above regarding inner clipboard buffer |
AppendFiles( files, isCut = 0 ) | Same as SetFiles() but appends list of files to the end instead of replacing them. All dublicate paths will be removed automatically |
iAppendFiles( files, isCut = 0 ) | Same as above regarding inner clipboard buffer |
GetBitmap() | Returns hBitmap if clipboard currenly has any picture on it. See exmaple below about how to use that |
iGetBitmap() | Same as above regarding inner clipboard buffer |
SetBitmap( bitmap ) | Sets bitmap on the clipboard bitmap – should be either full path to picture file or hBitmap Returns number of bytes finilazed clipboard has on success, or 0 otherwise Note: original clipboard data will not be cleared, so some applications may not “see” bitmap on clipboard if there is another format ( EXCEL for example ). Clear the clipboard data manually before inserting bitmap if you need so. |
iSetBitmap( bitmap ) | Same as above regarding inner clipboard buffer |
GetText() | Returns plain text from current Windows clipboard |
iGetText() | Same as above regarding inner buffer |
SetText( textData ) | Sets text to Windows clipboard. This is not repleace all data on the clipboard, but only specific format textData – any string returns number of bytes placed on clipboard. This includes ALL data clipboard has, not only the text part |
iSetText( textData ) | Same as above but works with inner clipboard buffer without changing the real Windows clipboard |
AppendText( textData ) | Same as SetText() but instead of replacing, it appends text to one clipboard already has |
iAppendText( textData ) | Same as above but for inner buffer |
GetHTML() | Returns raw html formatted data if Windows clipboard has one |
iGetHTML() | Same as above regarding inner buffer |
SetHTML( html, source = “” ) | Puts data on clipboard in HTML format html – data to place on clipboard source – source URL to specify for this data Returns number of bytes placed on clipboard |
iSetHTML( html, source = “” ) | Same as above regarding inner buffer |
iGetData( ByRefData ) | Copy data from inner clipboard Data – variable where clip data will be copied Returns number of bytes clip were copied There is NO such static method |
iSetData( ByRefData ) | Puts data to inner clipboard buffer. Data – buffer containing data previously got from iGetData |
IsEmpty() | Returns True if current Windows clipboard empty |
iIsEmpty() | Returns True if inner clipboard buffer has no data (empty) |
HasFormat( fmt ) | Returns non-zero if specified format available on clipboard fmt – named or numeric format to check |
iHasFormat( fmt ) | Same as above for inner clipboard buffer |
SaveBitmap( filePath, format ) | Saves bitmap data currently on clipboard to file filePath – full path to file where data will be saved format – should be one of the following: bmp,jpeg,gif,tiff,png |
iSaveBitmap( filePath, format ) | Same as above for inner buffer |
下边是使用的例子:
下边所有的例子都要添加以下两个头文件:
#Include WinClipAPI.ahk ;首先要包含这个,先后顺序有影响 #Include WinClip.ahk
Snap( ByRef data )
clipSize := WinClip.Snap( clipData )
;———- iSnap()
wc := new WinClip
clipSize := wc.iSnap() ;copies clip data into inner buffer for later using
Restore( ByRef data )
clipSize := WinClip.Snap( clipData ) bytesRestored := WinClip.Restore( clipData )
;———- iRestore()
wc := new WinClip
clipSize := wc.iSnap() ;copies clip data into inner buffer for later using
bytesRestored := wc.iRestore() ;restoring data back to clipboard
Clear()
clipSize := WinClip.Snap( clipData ) WinClip.Clear() ;clipboard is empty after this point bytesRestored := WinClip.Restore( clipData )
;———- iClear()
wc := new WinClip
clipSize := wc.iSnap() ;copies clip data into inner buffer for later using
wc.iClear() ;inner buffer will be emptied after this point
bytesRestored := wc.iRestore() ;nothing will be placed back to clipboard, old data will be kept
GetFormats()
objFormats := WinClip.GetFormats() list = for nFmt, params in objFormats { ; format_number : format_name : data_size : data_size again ; the "buffer" is an object member containing actual format data list .= "`n" nFmt " : " params.name " : " params.size " : " params.GetCapacity( "buffer " ) } msgbox % list
;———- iGetFormats()
wc := new WinClip
clipSize := wc.iSnap() ;copies clip data into inner buffer for later using
objFormats := wc.iGetFormats()
list =
for nFmt, params in objFormats
{
; format_number : format_name : data_size : data_size again
; the “buffer” is an object member containing actual format data
list .= “`n” nFmt ” : ” params.name ” : ” params.size ” : ” params.GetCapacity( “buffer ” )
}
msgbox % list
Save( filePath )
WinClip.Save( "clip.txt" )
;———- iSave( filePath )
wc := new WinClip
clipSize := wc.iSnap() ;copies clip data into inner buffer for later using
wc.iSave( “clip.txt” )
Load( filePath )
WinClip.Load( "clip.txt" )
;———- iLoad( filePath )
wc := new WinClip
wc.iLoad( “clip.txt” ) ;copying data from file into inner buffer
wc.iRestore() ;puts data from inner buffer to clipboard
Copy()
WinClip.Copy()
;———- iCopy()
wc := new WinClip
wc.iCopy() ;copying data to inner buffer without changing actual clipboard data
Paste()
WinClip.Paste() ;if you want just paste some text quickly WinClip.Paste( "SomeRawText" )
;———- iPaste()
wc := new WinClip
clipSize := wc.iSnap() ;copies clip data into inner buffer for later using
wc.Clear() ;clearing win clipboard
wc.iPaste()
bytesRestored := wc.iRestore()
SetText( textData )
WinClip.SetText( "hey, you!" )
;———- iSetText( textData )
wc := new WinClip
wc.iSetText( “hey, you!” )
wc.iRestore()
AppendText( textData )
WinClip.SetText( "hey, you!" ) WinClip.AppendText( "`nand you!" )
;———- iAppendText( textData )
wc := new WinClip
wc.iSetText( “hey, you!” )
wc.iAppendText( “`nand you!” )
wc.iRestore()
GetFiles()
;copy some files from explorer window first filesList := WinClip.GetFiles()
;———- iGetFiles()
wc := new WinClip
;copy some files from explorer window first
wc.iSnap()
filesList := wc.iGetFiles()
SetFiles()
WinClip.SetFiles( "C:\file1.txt`nC:\file2.txt" ) ;try to paste this faile in any explorer window now ;---------- iSetFiles wc := new WinClip wc.iSetFiles( "C:\file1.txt`nC:\file2.txt" ) wc.iRestore()
AppendFiles()
WinClip.SetFiles( "C:\file1.txt`nC:\file2.txt" ) WinClip.AppendFiles( "C:\file3.txt`nC:\file4.txt" ) ;all four files should be on clipboard now ;---------- iAppendFiles wc := new WinClip wc.iSetFiles( "C:\file1.txt`nC:\file2.txt" ) wc.iAppendFiles( "C:\file3.txt`nC:\file4.txt" ) wc.iRestore()
GetBitmap()
;copy any picture first hBitmap := WinClip.GetBitmap() Gui, Add, Picture,% "hwndPicHwnd +" SS_BITMAP := 0xE SendMessage,% STM_SETIMAGE := 0x0172,% IMAGE_BITMAP := 0,% hBitmap,, ahk_id %PicHwnd% DllCall("DeleteObject", "Ptr", hBitmap ) Gui, Show, w1000 h700
;——- iGetBitmap()
;copy any picture first
wc := new WinClip
wc.iSnap()
hBitmap := wc.iGetBitmap()
Gui, Add, Picture,% “hwndPicHwnd +” SS_BITMAP := 0xE
SendMessage,% STM_SETIMAGE := 0x0172,% IMAGE_BITMAP := 0,% hBitmap,, ahk_id %PicHwnd%
DllCall(“DeleteObject”, “Ptr”, hBitmap )
Gui, Show, w1000 h700
SetBitmap()
WinClip.SetBitmap( "C:\somepicture.jpg" ) ;it should be on clipboard right now
;——— iSetBitmap()
wc := new WinClip
wc.iSetBitmap( “C:\somepicture.jpg” )
wc.iRestore
;it should be on clipboard right now
GetText()
plainText := WinClip.GetText()
;——- iGetText()
wc := new WinClip
wc.iSnap()
plainText := wc.iGetText()
GetHTML()
;copy something from browser first rawHTML := WinClip.GetHTML()
;—- iGetHTML()
;copy something from browser first
wc := new WinClip
wc.iSnap()
rawHTML := wc.iGetHTML()
官网链接:https://autohotkey.com/board/topic/74670-class-winclip-direct-clipboard-manipulations/
nice,正好需要.
代码底色为深色,导致部分代码看不清,能否优化一下代码的显色方式,是更易阅读。
现在已经优化,还有问题及时反馈!