#Persistent SetWorkingDir,%A_ScriptDir% ;設置工做目錄 #MaxThreadsPerHotkey 5 ;最大熱鍵數量 #NoEnv ;#Warn #SingleInstance force ;單腳本運行 #WinActivateForce ;強制激活窗體 Process Priority,,High ;線程,主,高級 CoordMode, Mouse ;鼠標相對於屏幕 AutoTrim,on ;自動省略首尾的空格和Tab SetBatchLines -1 ;讓腳本無休眠地執行(換句話說,也就是讓腳本全速運行) ComObjError(0) ;禁用 COM 錯誤通告 Menu, Tray, UseErrorLevel ;阻止顯示對話框和終止線程 ; #NoTrayIcon Label_DefVar: global MyAppVer:="Kawvin加強剪貼板v2.0(Q285781427)" global MyClipBoard_ini:= "MyClipBoard.ini" global All_Modes:="一次複製屢次粘貼|屢次複製一次粘貼|同時使用2個剪貼板|臨時記事本|禁用" global Sel_Mode:= ;當前模式 global EnableSound:= ;啓用聲音 global CopyHotKey:= ;複製熱鍵 global PasteHotKey:= ;粘貼熱鍵 global BackHotKey:= ;屢次向前 global PrevHotKey:= ;屢次向後 global MenuHotKey:= ;菜單熱鍵 global ListWinHotKey:= ;列表窗體熱鍵 global LCopyHotKey:= ;用於顯示-複製熱鍵 global LPasteHotKey:= ;用於顯示-粘貼熱鍵 global LBackHotKey:= ;用於顯示-屢次向前 global LPrevHotKey:= ;用於顯示-屢次向後 global LMenuHotKey:= ;用於顯示-菜單熱鍵 global LListWinHotKey:= ;用於顯示-列表窗體熱鍵 global MyClipMenu:= ;定義剪貼板菜單 global CurWin_Title:= ;當前鼠標下的窗體標題 global MyUseTongPei :=0 ;設置是否啓用通配符 global MyPasteLine :=0 ;定義目前將要粘貼的行數 global MyClipArray:={} ;定義剪貼板歷史記錄 global MyMaxID:=0 ;最大序號 global MySel:= ;定義臨時存放變量 global MySelRich:= ;定義臨時存放變量 global MyAutoEnter := ;定義是否自動回車 global MyFirText:= ;第一剪貼板內容 global MySecText:= ;第二剪貼板內容 global MyWS:= ;位數 global MyStart:= ;起始序號 global MyEnd:= ;終止序號 global MySpace:= ;間距 Label_Start: iniRead,Sel_Mode,%MyClipBoard_ini%,通用設置,當前模式 iniRead,EnableSound,%MyClipBoard_ini%,通用設置,啓用聲音 iniRead,CopyHotKey,%MyClipBoard_ini%,通用設置,複製熱鍵 iniRead,PasteHotKey,%MyClipBoard_ini%,通用設置,粘貼熱鍵 iniRead,BackHotKey,%MyClipBoard_ini%,通用設置,屢次向前 iniRead,PrevHotKey,%MyClipBoard_ini%,通用設置,屢次向後 iniRead,MenuHotKey,%MyClipBoard_ini%,通用設置,菜單熱鍵 iniRead,ListWinHotKey,%MyClipBoard_ini%,通用設置,窗體熱鍵 ;替換熱鍵到正常鍵 LCopyHotKey:=MyFun_RetrunKeys(CopyHotKey) LPasteHotKey:=MyFun_RetrunKeys(PasteHotKey) LBackHotKey:=MyFun_RetrunKeys(BackHotKey) LPrevHotKey:=MyFun_RetrunKeys(PrevHotKey) LMenuHotKey:=MyFun_RetrunKeys(MenuHotKey) LListWinHotKey:=MyFun_RetrunKeys(ListWinHotKey) SkSub_CreatTrayMenu() Label_RegHotKey: CopyHotKey=$%CopyHotKey% PasteHotKey=$%PasteHotKey% BackHotKey=$%BackHotKey% PrevHotKey=$%PrevHotKey% MenuHotKey=$%MenuHotKey% ListWinHotKey=$%ListWinHotKey% if (Sel_Mode!="禁用") { hotkey,%CopyHotKey%,Label_Copy hotkey,%PasteHotKey%,Label_Paste hotkey,%BackHotKey%,Label_PasteBack hotkey,%PrevHotKey%,Label_PastePrev hotkey,%MenuHotKey%,TrayHandle_ShowMyClipArrayMenu hotkey,%ListWinHotKey%,TrayHandle_ShowListWin } Label_DrawGUI: gui Destroy if Sel_Mode=一次複製屢次粘貼 { gui Main:+AlwaysOnTop Gui Font, w700 cRed Gui, Add, Text, x10 y5 h20 , 複製/添加:%LCopyHotKey%,1次粘貼:%LPasteHotKey%,②屢次向:前%LBackHotKey%/後%LPrevHotKey% Gui Font Gui, Add, Edit, vMyFirText x12 y22 w360 h330 , Gui Font, w700 cRed Gui, Add, CheckBox, Checked vMyAutoEnter gLabel_AutoEnter x230 y360 w210 h20 , 粘貼後自動回車 Gui Font Gui, Add, Button, gLabel_GetData x20 y360 w80 h35 , ①數據確認 Gui, Add, Button, gLabel_Clear x102 y360 w80 h35 , 清空重置 Gui Font, s10 w700 cRed gui,Add,Text,x195 y382 h20,當前模式:%Sel_Mode% Gui Font Gui, Show, x127 y87 h402 w385, %MyAppVer% } if Sel_Mode=屢次複製一次粘貼 { gui Main:+AlwaysOnTop Gui Font, w700 cRed Gui, Add, Text, x10 y5 h20 ,複製/添加:%LCopyHotKey%,粘貼:%LPasteHotKey% Gui Font Gui, Add, Edit, vMyFirText x12 y22 w360 h330 , Gui Font, w700 cRed Gui, Add, CheckBox, Checked vMyAutoEnter gLabel_AutoEnter x230 y360 w210 h20 , 粘貼後自動回車 Gui Font ;Gui, Add, Button, gLabel_GetData x20 y360 w80 h35 , 數據確認 Gui, Add, Button, gLabel_Clear x102 y360 w80 h35 , 清空重置 Gui Font, s10 w700 cRed gui,Add,Text,x195 y382 h20,當前模式:%Sel_Mode% Gui Font Gui, Show, x127 y87 h402 w385, %MyAppVer% } if Sel_Mode=同時使用2個剪貼板 { gui Main:+AlwaysOnTop Gui Font, w700 cRed Gui, Add, Text, x10 y5 h20 , 第1剪切板(複製:Alt+F11,粘貼:%LBackHotKey%) Gui Font Gui, Add, Edit, vMyFirText x12 y22 w360 h185 , Gui Font, w700 cRed Gui, Add, Text, x12 y213 h20 , 第2剪切板(複製:Alt+F12,粘貼:%LPrevHotKey%) Gui, Add, CheckBox, vMyUseTongPei gLabel_EnabledTongPei x273 y210 w120 h20 , 啓用通配符(*) Gui Font Gui, Add, Edit, vMySecText x12 y230 w360 h90 , Gui, Add, Text, x12 y334 w30 h20 , 位數 Gui, Add, Edit, vMyWS x38 y330 w50 h20 , Gui, Add, UpDown, range1-9 x82 y330 w20 h20 , 1 Gui, Add, Text, x108 y334 w30 h20 , 起始 Gui, Add, Edit, vMyStart x134 y330 w50 h20 , 1 Gui, Add, UpDown, range1-999 x162 y330 w20 h20 , 1 Gui, Add, Text, x204 y334 w30 h20 , 終止 Gui, Add, Edit, vMyEnd x230 y330 w50 h20 , Gui, Add, UpDown, range1-999 x212 y330 w20 h20 , 99 Gui, Add, Text, x295 y334 w30 h20 , 間距 Gui, Add, Edit, vMySpace x322 y330 w50 h20 , Gui, Add, UpDown, range1-999 x352 y330 w20 h20 , 1 Gui Font, w700 cRed Gui, Add, CheckBox, Checked vMyAutoEnter gLabel_AutoEnter x230 y360 w210 h20 , 粘貼後自動回車 Gui Font ;Gui, Add, Button, gLabel_GetData x20 y360 w80 h35 , 數據確認 Gui, Add, Button, gLabel_Clear x102 y360 w80 h35 , 清空重置 Gui Font, s10 w700 cRed gui,Add,Text,x195 y382 h20,當前模式:%Sel_Mode% Gui Font Gui, Show, x127 y87 h402 w385, %MyAppVer% } if Sel_Mode=臨時記事本 { gui Main:+AlwaysOnTop Gui Font, w700 cRed Gui, Add, Text, x10 y5 h20 , 複製/添加:%LCopyHotKey%,1次粘貼:%LPasteHotKey%,②屢次向:前%LBackHotKey%/後%LPrevHotKey% Gui Font Gui, Add, Edit, vMyFirText x12 y22 w360 h330 , Gui Font, w700 cRed Gui, Add, CheckBox, Checked vMyAutoEnter gLabel_AutoEnter x230 y360 w210 h20 , 粘貼後自動回車 Gui Font Gui, Add, Button, gLabel_GetData x20 y360 w80 h35 , ①數據確認 Gui, Add, Button, gLabel_Clear x102 y360 w80 h35 , 清空重置 Gui Font, s10 w700 cRed gui,Add,Text,x195 y382 h20,當前模式:%Sel_Mode% Gui Font Gui, Show, x127 y87 h402 w385, %MyAppVer% } WinGet, MyID, ID, A ; 獲取 窗體ID. WinGetPos,,, MyWindowWidth, MyWindowHeight, A ;---- 放置屏幕鍵盤在屏幕的底部(考慮到任務欄的位置): SysGet, MyWorkArea, MonitorWorkArea, %MyMonitor% ; 計算用戶窗體X座標: MyWindowX = %MyWorkAreaRight% MyWindowX -= %MyWorkAreaLeft% ; 如今 MyWindowX 包含了顯示器的寬度. MyWindowX -= %MyWindowWidth% MyWindowX += %MyWorkAreaWidth% ; 計算水平靠右的位置. ; 如下操做是爲了防止窗體不是主顯示器,或者任務欄停靠在屏幕左側: MyWindowX += %MyWorkAreaLeft% ; 計算用戶窗體Y座標: MyWindowY = %MyWorkAreaBottom% MyWindowY -= %MyWindowHeight% WinMove, A,, %MyWindowX%, %MyWindowY% WinSet, AlwaysOnTop, On, ahMyid %MyID% ;WinSet, TransColor, %TransColor% 220, ahMyid %MyID% return ;========================= ;個人過程 SkSub_CreatTrayMenu() { Menu,Tray,DeleteAll Menu, Tray, NoStandard ;自定義菜單放在標準菜單上面 iniRead,Sel_Mode,%MyClipBoard_ini%,通用設置,當前模式 if Sel_Mode=禁用 menu,tray,icon,ICONS\KCx.ico else menu,tray,icon,ICONS\KC.ico loop,parse,All_Modes,`| { if A_LoopField!= { Menu, tray, add,%A_LoopField%,TrayHandle_ModeChange if (A_LoopField=Sel_Mode) menu,tray,Check ,%A_LoopField% } } Menu,tray, add ; 分隔符 menu,tray,add,清空剪貼板,TrayHandle_ClearCllipBoard Menu, tray, add ,剪貼板序列菜單,TrayHandle_ShowMyClipArrayMenu Menu, tray, add ,顯示剪貼板列表窗體,TrayHandle_ShowListWin Menu, tray, add ; 分隔符 Menu,tray, add,參數設置,TrayHandle_EditSetting Menu,tray, add ; 分隔符 Menu, tray, add ,退出,TrayHandle_Exit Menu, Tray, Default, 剪貼板序列菜單 Menu, Tray, Click, 1 } return SkSub_CreatMyClipArrayMenu() { if MyClipArray.Length()<=1 return Menu,MyClipMenu,DeleteAll loop % MyClipArray.Length() { MyClipItem:= if strlen(MyClipArray[A_Index])>20 { MyClipItem:=substr(MyClipArray[A_Index],1,20) . "......" } else { MyClipItem:=% MyClipArray[A_Index] } menu,MyClipMenu,add,%MyClipItem%,MenuHandle_SetMenuItemToClipBoard menu,MyClipMenu,Icon,%MyClipItem%,ICONS\%A_Index%.ico } menu,MyClipMenu,add menu,MyClipMenu,add,清空歷史記錄,MenuHandle_ClearMenuItem ;Menu, MyClipMenu, Show } return TrayHandle_ShowMyClipArrayMenu: { ;MouseGetPos,Menu_X, Menu_Y MouseGetPos,,,CurWin_id ;當前鼠標下的進程ID WinGet, CurWin_Fullpath,ProcessPath,Ahk_ID %CurWin_id% ;當前進程的路徑 WinGetTitle, CurWin_Title,Ahk_ID %CurWin_id% ;當前進程的標題 Menu, MyClipMenu, Show } return MenuHandle_SetMenuItemToClipBoard: MyPasteLine:=A_ThisMenuItemPos ClipBoard:=MyClipArray[MyPasteLine] ClipWait,0.5 send,^{vk56} return MenuHandle_ClearMenuItem: MyClipArray:={} Clipboard:= Menu,MyClipMenu,DeleteAll return TrayHandle_ShowListWin: gosub ,Label_GetData GuiControlGet,MyFirText,,MyFirText MouseGetPos,,,CurWin_id ;當前鼠標下的進程ID WinGet, CurWin_Fullpath,ProcessPath,Ahk_ID %CurWin_id% ;當前進程的路徑 WinGetTitle, CurWin_Title,Ahk_ID %CurWin_id% ;當前進程的標題 Gui MyListWin:New Gui MyListWin:+AlwaysOnTop Gui MyListWin:Font, s12 Gui MyListWin:Add,Text, x5 y13 h21,指定的程序: Gui,MyListWin:Add, DropDownList,x100 y10 w300 vactivewindow, Gui MyListWin:Add,Button,x405 y9 w70 gMySub_RefreshList,刷新 MySub_RefreshList() MyListItems:= if MyClipArray.Length()=0 return loop % MyClipArray.Length() { if (A_Index=1) MyListItems:=MyClipArray[A_Index] else MyListItems:=MyListItems . "|" . MyClipArray[A_Index] } Gui MyListWin:Add,ListBox, x5 w470 h465 vMyListItem gMySub_PastMyListItem, %MyListItems% Gui MyListWin:Font Gui MyListWin:Show, w480 h500, 剪貼板列表 return TrayHandle_ClearCllipBoard: Clipboard:= return TrayHandle_ModeChange: Sel_Mode:=A_ThisMenuItem iniwrite,%Sel_Mode%,%MyClipBoard_ini%,通用設置,當前模式 Reload return TrayHandle_EditSetting: ;gui Destroy gui MySetWin:New ;Gui MySetWin:+OwnerMain gui MySetWin:+AlwaysOnTop Gui MySetWin:Font, s12 Gui MySetWin:Add, GroupBox, x11 y6 w315 h185, 熱鍵指定:通用 Gui MySetWin:Font Gui MySetWin:Font, s11 Gui MySetWin:Add, Text, x25 y35 w105 h23 +0x200 Right, 複製: Gui MySetWin:Add, Edit, x145 y35 w165 h21 Gui MySetWin:Add, Text, x25 y65 w105 h23 +0x200 Right, 一次性粘貼: Gui MySetWin:Add, Edit, x145 y65 w165 h21 Gui MySetWin:Add, Text, x25 y95 w105 h23 +0x200 Right, 向前粘貼: Gui MySetWin:Add, Edit, x145 y95 w165 h21 Gui MySetWin:Add, Text, x25 y125 w105 h23 +0x200 Right, 向後粘貼: Gui MySetWin:Add, Edit, x145 y125 w165 h21 Gui MySetWin:Add, Text, x25 y155 w105 h23 +0x200 Right, 彈出菜單: Gui MySetWin:Add, Edit, x145 y155 w165 h21 Gui MySetWin:Add, Button, x65 y205 w75 h30, 確認 Gui MySetWin:Add, Button, gWinSetButtonCancel x200 y205 w75 h30, 取消 Gui MySetWin:Font Gui MySetWin:Show, w340 h250, 參數設置 return MySub_RefreshList() { droplist:= GuiControl,MyListWin:,activewindow,| WinGet, id, list,,, Program Manager Loop, %id% { this_id := id%A_Index% WinGetTitle, this_title, ahk_id %this_id% if this_title= continue if (this_title=CurWin_Title) droplist=%droplist%%this_title%|| else droplist=%droplist%%this_title%| } GuiControl,MyListWin:,activewindow, %droplist% ;Gui, MyListWin:Add, DropDownList,x100 y5 w370 vactivewindow, %droplist% } MySub_PastMyListItem() { GuiControlget,activewindow,MyListWin: ;MsgBox % activewindow if A_GuiEvent =DoubleClick { ClipBoard:=MyClipArray[A_EventInfo] sleep 100 ;WinWaitActive, %CurWin_Title% ,,5 WinActivate, %activewindow% send,^{vk56} } } WinSetButtonCancel: { Gui MySetWin:Destroy return } MySetWin確認: { Gui MySetWin:Destroy return } Label_Copy: if (Sel_Mode="一次複製屢次粘貼" or Sel_Mode="屢次複製一次粘貼" or Sel_Mode="臨時記事本") { Clipboard = Send, ^{vk43} ClipWait,0.5 if ( ErrorLevel ) ;若是沒有選擇到什麼東西,則退出 Return if MyFirText= MyFirText=%Clipboard% else MyFirText=%MyFirText%`n%Clipboard% Clipboard = GuiControl,,MyFirText,%MyFirText% } return Label_Paste: Critical, On GuiControlget, MyAutoEnter GuiControlget, MyFirText if (Sel_Mode="一次複製屢次粘貼" or Sel_Mode="屢次複製一次粘貼" or Sel_Mode="臨時記事本") { if MyFirText= return else { if MyClipArray.Length()=0 Clipboard:=MyFirText sleep 100 if (MyAutoEnter=1) ;若是自動回車 { send,^{vk56} send,{Enter} } else { send,^{vk56} } Clipboard:= } } return !F11:: Critical, On if Sel_Mode=同時使用2個剪貼板 { GuiControl,,MyFirText, Clipboard = Send, ^{vk43} ClipWait,0.5 if ( ErrorLevel ) ;若是沒有選擇到什麼東西,則退出 Return GuiControl,,MyFirText,%Clipboard% Clipboard = } return !F12:: Critical, On if Sel_Mode=同時使用2個剪貼板 { GuiControl,,MySecText, Clipboard = Send, ^{vk43} ClipWait,0.5 if ( ErrorLevel ) ;若是沒有選擇到什麼東西,則退出 Return GuiControl,,MySecText,%Clipboard% Clipboard = } return Label_PasteBack: Critical, On GuiControlget, MyAutoEnter if (Sel_Mode="一次複製屢次粘貼" or Sel_Mode="臨時記事本") { if (MyPasteLine=-1) ;粘貼行數-1時,退出 Return MyPasteLine -=1 if (MyPasteLine <1) ;粘貼行數大於最大行數,不粘貼 { MyPasteLine:=0 return } Clipboard:=MyClipArray[MyPasteLine] sleep 100 if (MyAutoEnter=1) ;若是自動回車 { send,^{vk56} send,{Enter} } else { send,^{vk56} } Clipboard:= } if (Sel_Mode="同時使用2個剪貼板") { GuiControlGet, MyFirText if MyFirText= return else { Clipboard:=MyFirText sleep 100 if (MyAutoEnter=1) ;若是自動回車 { send,^{vk56} send,{Enter} } else { send,^{vk56} } Clipboard:= } } return Label_PastePrev: Critical, On GuiControlget, MyAutoEnter if (Sel_Mode="一次複製屢次粘貼" or Sel_Mode="臨時記事本") { if (MyPasteLine=-1) ;粘貼行數-1時,退出 Return MyPasteLine +=1 if (MyPasteLine > MyMaxID) ;粘貼行數大於最大行數,不粘貼 { MyPasteLine:=MyMaxID+1 return } Clipboard:=MyClipArray[MyPasteLine] sleep 100 if (MyAutoEnter=1) ;若是自動回車 { send,^{vk56} send,{Enter} } else { send,^{vk56} } Clipboard:= } if (Sel_Mode="同時使用2個剪貼板") { GuiControlGet, MySecText GuiControlGet, MyWS GuiControlGet, MyStart GuiControlGet, MyEnd GuiControlGet, MySpace GuiControlGet, MyUseTongPei if MySecText= ;第二剪貼板爲空,退出 Return if (MyUseTongPei=0) ;不啓用通配符 { Clipboard:=MySecText sleep 100 if (MyAutoEnter=1) ;若是自動回車 { send,^{vk56} send,{Enter} } else { send,^{vk56} } Clipboard:= } if (MyUseTongPei=1) ;啓用通配符 { if (MyStart<MyEnd+1) ;若是起始值小於終止值 { MyTemStr:=MySecText ;MyPiPei:=MyFun_MakeN0(MyStart,MyWS) MyPiPei:=substr("000000000" . MyStart,1-MyWS) stringreplace,MyTemStr,MyTemStr,(*),%MyPiPei%,all MyStart:=MyStart+MySpace GuiControl,,MyStart,%MyStart% Clipboard:=MyTemStr sleep 100 if (MyAutoEnter=1) ;若是自動回車 { send,^{vk56} send,{Enter} } else { send,^{vk56} } Clipboard:= } } } return ; 粘貼後自動回車 Label_AutoEnter: { if (MyAutoEnter=1) MyAutoEnter:=0 else MyAutoEnter:=1 return } ; 清空重置 Label_Clear: { MyPasteLine:=-1 MyClipArray:={} MyMaxID:=0 MyFirText:= MySecText:= MyWS:=1 MyStart:=1 MyEnd:=99 MySpace:=1 GuiControl,,MyFirText, GuiControl,,MySecText, GuiControl,,MyWS,1 GuiControl,,MyStart,1 GuiControl,,MyEnd,99 GuiControl,,MySpace,1 ;清空菜單 Clipboard:= Menu,MyClipMenu,DeleteAll Return } ; 獲取數據 Label_GetData: { GuiControlGet, MyFirText MyClipArray:={} if (Sel_Mode="一次複製屢次粘貼" or Sel_Mode="臨時記事本") { ;讀取內容到數組 loop,parse,MyFirText,`n`|,`r { TemStr:=A_LoopField if (TemStr="") continue MyClipArray.push(Temstr) } MyMaxID:=MyClipArray.Length() MyPasteLine:=0 } ;建立菜單 SkSub_CreatMyClipArrayMenu() return } ; 啓用通配符 Label_EnabledTongPei: { if (MyUseTongPei =0) { MyUseTongPei :=1 GuiControlGet,MySecText,,MySecText GuiControl,,MySecText,%MySecText%(*) }else { MyUseTongPei :=0 GuiControlGet,MySecText,,MySecText StringReplace,MySecText,MySecText,(*),,All GuiControl,,MySecText,%MySecText% } return } MyFun_RetrunKeys(HotKeyString) { StringReplace,HotKeyString,HotKeyString,`+,Shift`+,All StringReplace,HotKeyString,HotKeyString,`!,Alt`+,All StringReplace,HotKeyString,HotKeyString,`^,Ctrl`+,All StringReplace,HotKeyString,HotKeyString,`#,Win`+,All return , % HotKeyString } GuiClose: TrayHandle_Exit: ExitApp