/SRC/Ahk/candy.ahk
AutoHotKey | 377 lines | 291 code | 37 blank | 49 comment | 7 complexity | 5692a00420f6dbd7eaf165853976c9ff MD5 | raw file
- ;This is the autohotkey version.
- Process Priority,,High
- ;#NoTrayIcon
- #SingleInstance Ignore
- #Include sub/urlencode.ahk
- #Include sub/ini.ahk
- #Include sub/web_search.ahk
- #Include sub/get_processname.ahk
- #Include sub/asc_count.ahk
- SetWorkingDir,%A_ScriptDir% ;ÉèÖù¤×÷Ŀ¼ΪcandyËùÔÚĿ¼
- splitpath,A_ScriptDir,,,,,script_driver ;candyËùÔÚµÄÅÌ·û
-
- ;ÌáÈ¡ÃüÁîÐÐ
- If 0>0
- {
- Loop, %0%
- {
- tmp := %A_Index%
- If InStr( tmp, "/ini=", TRUE ) = 1
- StringReplace ,Settings_file,tmp,/ini=
- Else
- CommandLineInput=%CommandLineInput%%A_Space%%tmp%
- }
- }
- CandyInit:
- If Settings_file=
- {
- StringReplace, Settings_file, A_ScriptName, .exe, .ini
- }
- IfNotExist,%Settings_file%
- {
- Msgbox Usage: `n------------------------------`nThe name of your configuration file must be same as the executable file. %Settings_file%`nOr run with parameters "%A_ScriptName% /ini=anyname.ini" `n
- ;exitapp
- return
- }
- ini_Load(src,Settings_file)
- return
-
- CandyGo:
- WinGet,currwin_pid,pid,A ;µ±Ç°´°¿ÚµÄPID
- WinGetClass, currwin_class, A ;µ±Ç°´°¿ÚµÄclass
- WinGetTitle, currwin_Title, A ;µ±Ç°´°¿ÚµÄTitle
- ControlGet, currwin_hwnd,Hwnd,,,A ;µ±Ç°´°¿ÚµÄHandle
- currwin_fullpath:=GetModuleFileNameEx(currwin_pid) ;µ±Ç°´°¿ÚµÄfullpath
- splitpath,currwin_fullPath,,,,currwin_name, ;Çиǰ´°¿ÚµÄ·¾¶£¬»ñÈ¡´°¿ÚµÄname
-
- /*
- ÌáÈ¡Ä¿±ê
- */
-
- If CommandLineInput!= ;Èç¹ûÓÐÃüÁîÐвÎÊý£¬Ìø¹ýCTRL CÈ¡Ä¿±ê
- {
- f_fileselected=%CommandLineInput%
- Goto Lable_CommandLineInput
- }
- ;**************************************************************************************************************************
- ;ûÓÐÃüÁîÐвÎÊý£¬ÔòÒª¿¿CTRL CÈ¡Ä¿±êÁË
- IniRead,p_timewait_for_candy,%settings_file%,configuration,TimeWaitCandy,0.4
- Saved_ClipBoard := ClipboardAll
- clipboard =
- Send, ^c
- ClipWait,%p_timewait_for_candy%
- f_fileselected=%Clipboard%
- Clipboard := Saved_ClipBoard
- Saved_ClipBoard =
-
-
- ;**************************************************************************************************************************
- is_windowflag:=0
- If f_fileselected= ;Èç¹ûÕ³Ìù°åÀïÃæûÓÐÄÚÈÝ£¬Ôò½øÐÐcandywindows½ø³Ì
- {
- f_FileExt:="window"
- f_fileselected=%currwin_name%
- is_windowflag:=1
- GOTO Lable_WindowSelected
- ;;ExitApp
- return
- }
-
- ;ÌáÈ¡ºó׺
- Lable_CommandLineInput:
- IniRead,p_ShortText_length,%settings_file%,configuration,ShortText_length,80 ;¶ÌÎı¾µÄ³¤¶È
- IfExist,%f_fileselected% ;Èç¹ûÊǵçÄÔÀïÃæ´æÔÚµÄÎļþ
- {
- FileGetAttrib, f_file_Attrib, %f_fileselected% ;ÊÇÎļþµÄÇé¿öÏ£¬Çø·ÖÊÇ·ñÎļþ¼Ð,°Ñ Path Ö¸ÏòµÄÎļþ»òÎļþ¼ÐµÄÊôÐÔ¸³Öµ¸ø Attrib
- IfInString, f_file_Attrib, D ;Èç¹ûÔÚ Attrib ÀïÓÐ D ,¾Í±íʾÕâ¸ö·¾¶´ú±íµÄÊÇÎļþ¼Ð£¬·ñÔò¾ÍÊÇÎļþ
- {
- If(RegExMatch(f_fileselected,":\\$"))
- {
- f_FileExt:="Driver" ;ÊÇ·ñÅÌ·û
- }
- Else
- {
- f_FileExt:="Folder" ;ÊÇ·ñÎļþ¼Ð
- }
- SplitPath,f_fileselected,,f_FilePath,,f_filefoldernameonly,f_FileDriver
- }
- Else ;Èô²»ÊÇÎļþ¼ÐµÄ»°£¬ÔòÖ»ÄÜÊÇÎļþÁË
- {
- is_fileflag:=1
- splitpath,f_fileselected,f_FileName,f_FilePath,f_FileExt,f_FileNamenoext,f_FileDriver
- SplitPath,f_FilePath,,,,f_filefoldernameonly,
- ;StringReplace,f_FileDriverletter,f_FileDriver,: ;±»Ñ¡ÎļþµÄÅÌ·û£¬²»´øðºÅ
- If !f_FileExt ;ûÓкó׺µÄÎļþ
- {
- f_FileExt:="NoExt"
- }
- }
- }
- Else ;Èç¹ûÊÇÎı¾
- {
- is_textflag:=1
- If(RegExMatch(f_fileselected,"i)^(https://|http://|www.)([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"))
- {
- f_FileExt:="WebUrl" ;ÅжÏÊÇ·ñÍøÖ·
- }
- Else If(RegExMatch(f_fileselected, "^[\w-_.]+@(?:\w+(?::\d+)?\.){1,3}(?:\w+\.?){1,2}$"))
- {
- f_FileExt:="Email" ;ÅжÏÊÇ·ñemailµØÖ·
- }
- Else If (strlen(f_fileselected)<p_ShortText_length)
- {
- f_FileExt:="ShortText" ;ÅжÏÊÇ·ñ¶ÌÎı¾
- }
- Else
- {
- f_FileExt:="LongText" ;ÅжÏÊÇ·ñ³¤Îı¾
- }
- }
-
-
- ;¶ÔÄܹ»Ó®
-
- Lable_WindowSelected: ;Èç¹ûÊÇwindowsÔòÖ±½ÓÌøµ½ÕâÀïÀ´£¬±ÜÃâ±»ÈÏΪÊÇ0³¤¶ÈµÄshort_text
- abc=i)(^|\|)%f_fileext%($|\|) ;ÕýÔò±í´ïʽ°¡£¬ºÃÐÁ¿àµÄ£¬|±ØÐëÒªÓÐ \¿ªµÀ
- f_fileext_group:=ini_FindKeysRE(src, "associations", abc)
- IniRead,MyAppName, %Settings_file%,associations,%f_fileext_group%, ;ÔÚiniÎļþÀïÃæÕÒÆ¥Åä
-
-
-
- If MyAppName=Error ;Èç¹ûûÓÐÏàÓ¦ºó׺µÄ¶¨Òå
- {
- If is_fileflag=1 ;Èç¹ûûÓж¨Ò壬ÈôÊÇÎļþµÄ»°£¬¿´ÊÇ·ñÓÐanyfileµÄ¶¨Òå
- {
- IniRead,MyAppName, %Settings_file%,associations,AnyFile
- If MyAppName=Error
- {
- Run,%f_fileselected%, ,useerrorlevel ;UseErrorLevelÈç¹ûrunÃüÁîʧ°Ü£¬ºöÂÔ³ö´íÌáʾ²¢ÖÃerrorlevelΪError£¬Ï̼߳ÌÐøÍùÏ¡£
- ;ExitApp
- return
- }
- }
- Else if is_textflag=1 ;Èç¹ûûÓж¨Ò壬ºó׺ÊÇÎı¾£¬¿´ÊÇ·ñÓÐanytextµÄ¶¨Òå
- {
- IniRead,MyAppName, %Settings_file%,associations,AnyText
- If MyAppName=Error
- {
- ;ExitApp
- return
- }
- }
- Else ;ÆäËüµÄºó׺ÊÇÎļþ¼Ð¡¢ÅÌ·û¡¢´°ÌåµÈÁË£¬ÕâÖÖÇé¿öÏÂÖ±½ÓÍ˳ö³ÌÐò¼´¿É
- {
- ;ExitApp
- return
- }
- }
-
-
-
- ;**************************************************************************************************************************
- ;ÅжÏÊÇQuickCandy£¬»¹ÊÇmenuCandy
- If(RegExMatch(MyAppName,"i)^(menu_)")) ;Èç¹ûÊÇÒÔmenu_¿ªÍ·,ÏÈÈ¥»²Ëµ¥
- Goto Lable_DrawMenu
- Else ;·ñÔòÖ±½ÓÔËÐÐÓ¦ÓóÌÐò
- Goto Lable_RunApp
-
-
-
-
- Lable_DrawMenu:
- ;================²Ëµ¥µÚÒ»ÐУ¬ÏÞÖÆ×ÖÊýÔÚ20¸ö×Ö================================
- f_length_fileselected:=StrLen(f_fileselected)
- IfGreater,f_length_fileselected,20
- {
- stringleft,f_textmenu_left,f_fileselected,5
- StringMid, tmp, f_fileselected, 6, 1
- If (! IsChar(tmp) && Mod(AscCount(f_textmenu_left), 2) = 0 ) ;5¸ö×Ö·ûÖÐÓÐżÊý¸öASCII£¬¶àÈ¡Ò»¸ö×Ö½Ú
- {
- stringleft,f_textmenu_left,f_fileselected,6
- StringRight,f_textmenu_right,f_fileselected,11
- If (Mod(AscCount(f_textmenu_right), 2) = 0) ;11¸ö×Ö·ûÖÐÓÐżÊý¸öASCII£¬Ö»ÄÜÉÙÈ¡Ò»¸ö×Ö½Ú
- StringRight,f_textmenu_right,f_fileselected,10
- }
- Else
- {
- StringRight,f_textmenu_right,f_fileselected,12
- If (! IsChar(f_textmenu_right) && Mod(AscCount(f_textmenu_right), 2) = 1) ;12¸ö×Ö·ûÖÐÓÐÆæÊý¸öASCII£¬ÉÙÈ¡Ò»¸ö×Ö½Ú
- StringRight,f_textmenu_right,f_fileselected,11
- }
- menu mymenu,add,%f_textmenu_left% ¡ %f_textmenu_right%,r_CopyFullPath ;¼ÓµÚÒ»Ðв˵¥£¬ÏÔʾѡÖеÄÄÚÈÝ£¬¸Ã²Ëµ¥ÈÃÄ㿽±´ÆäÄÚÈÝ
- }
- Else
- {
- Menu mymenu,add,%f_fileselected%,r_CopyFullPath ;¼ÓµÚÒ»Ðв˵¥£¬ÏÔʾѡÖеÄÄÚÈÝ£¬¸Ã²Ëµ¥ÈÃÄãÖ±½Ó´ò¿ªÅäÖÃÎļþ
- }
- ;================¸ù¾Ý¸÷ÀàÐÍ»³ö²Ëµ¥================================
- IfInString,MyAppName,@
- {
- f_Menu_additional:=1
- StringReplace,MyAppName,MyAppName,@
- }
-
- key:=ini_GetKeys(src,MyAppName) ;µ÷ÓÃʱ£¬Èç¹ûÊDZäÁ¿¾Í²»ÓüÓ%%
- if key!=
- {
- menu mymenu,add
- Loop,Parse,key,`n
- {
- Menu,mymenu,Add,%A_LoopField%,r_Menu_handle
- }
- }
- If f_Menu_additional=1 ;Èç¹ûûÓÐ@£¬Ôò²»ÓÃÏÔʾ¸½¼ÓµÄ²Ëµ¥
- {
- menu mymenu,add
- f_Menu_additional:=0
- f_key_Menu_AnyFile:=ini_GetKeys(src,"Menu_AnyFile") ;µ÷ÓÃʱ£¬Èç¹ûÊdz£Á¿£¬Ò»¶¨Òª¼Ó""
- Loop,Parse,f_key_Menu_AnyFile,`n
- {
- Menu,mymenu,Add,%A_LoopField%,r_Menu_handle_AnyFile
- }
- }
-
- Menu,MyMenu,Show
- Menu, MyMenu, DeleteAll
- ;ExitApp
- return
-
-
- ;================²Ëµ¥´¦Àí================================
- r_Menu_handle:
- MyAppName:=ini_Read(src,MyAppName,A_ThisMenuItem)
- Goto Lable_RunApp
-
- r_Menu_handle_AnyFile:
- MyAppName:=ini_Read(src,"Menu_AnyFile",A_ThisMenuItem)
- Goto Lable_RunApp
-
-
- r_CopyFullPath:
- Clipboard:=f_fileselected
- ;ExitApp
- return
-
-
-
- /*
- ¨X¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨[
- ¨U ÔËÐд¦Àí¢ÚÔËÐд¦Àí ¨U
- ¨^¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨a
- */
-
- Lable_RunApp:
- If(RegExMatch(MyAppName,"i)^(https://|http://|www.)([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?")) ;Èç¹ûÊÇÍøÒ³ËÑË÷£¬ÒÔhttp¿ªÍ·£¬×ª³Éutf8
- {
- f_fileselected:=url2UTF8(f_fileselected)
- f_ÍøÖ·=%MyAppName%%f_fileselected%
- mywebrun:=websearch(Settings_file,f_ÍøÖ·,currwin_class,currwin_fullpath)
- Run, %mywebrun%,,useerrorlevel
- ;ExitApp
- return
- }
- If(RegExMatch(MyAppName,"i)^(@https://|@http://|@www.)([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?")) ;Èç¹ûÊÇÍøÒ³ËÑË÷£¬ÒÔ@http¿ªÍ·£¬×ª³Égbk
- {
- StringTrimLeft,MyAppName,MyAppName,1
- f_fileselected:=url2gbk(f_fileselected)
- f_ÍøÖ·=%MyAppName%%f_fileselected%
- mywebrun:=websearch(Settings_file,f_ÍøÖ·,currwin_class,currwin_fullpath)
- Run, %mywebrun%,,useerrorlevel
- ;ExitApp
- return
- }
- ;=========================================
- Else ;²»ÊÇÍøÖ·£¬ÔòÊÇÒ»°ãµÄÓ¦ÓóÌÐò
- {
- ;Ìæ»»µôµ±Ç°´°¿ÚÄÇÒ»²¿·ÖµÄ
- StringReplace,MyAppName,MyAppName,<win_class> ,%currwin_class%,All
- StringReplace,MyAppName,MyAppName,<win_title> ,%currwin_title%,All
- StringReplace,MyAppName,MyAppName,<win_hwnd> ,%currwin_hwnd%
- StringReplace,MyAppName,MyAppName,<win_name> ,%currwin_name%,All
- StringReplace,MyAppName,MyAppName,<win_fullpath> ,%currwin_fullpath%
- ;Ä¿µÄÊÇÏà¶Ô·¾¶
- StringReplace,MyAppName,MyAppName,<cp>,%A_ScriptDir%,All
- StringReplace,MyAppName,MyAppName,<cd>,%script_driver%,All
- ;һЩʱ¼ä²ÎÊý
- StringReplace,MyAppName,MyAppName,<year> ,%A_YEAR%,All
- StringReplace,MyAppName,MyAppName,<mon> ,%A_MM%,All
- StringReplace,MyAppName,MyAppName,<date> ,%A_dd%,All
- StringReplace,MyAppName,MyAppName,<hour> ,%A_YEAR%,All
- StringReplace,MyAppName,MyAppName,<min> ,%A_Min%,All
- StringReplace,MyAppName,MyAppName,<sec> ,%A_Sec%,All
- StringReplace,MyAppName,MyAppName,<wday> ,%A_WDay%,All
- StringReplace,MyAppName,MyAppName,<now> ,%A_Now%,All
- ;²Ù×÷¶ÔÏóÊÇÎļþµÄʱºò£¬½øÐÐÌæ»»µÄ¶ÔÏó
- StringReplace,MyAppName,MyAppName,<file_driver> ,%f_FileDriver%,All ;
- StringReplace,MyAppName,MyAppName,<file_path> ,%f_FilePath%,All ;²»´øÎļþÃûµÄ·¾¶
- StringReplace,MyAppName,MyAppName,<file_name> ,%f_FileNamenoext%,All ;´¿´âµÄÎļþÃû£¬ÎÞºó׺£¬ÎÞ·¾¶
- StringReplace,MyAppName,MyAppName,<file_ext> ,%f_FileExt%,All
- StringReplace,MyAppName,MyAppName,<file_foldername> ,%f_filefoldernameonly%,All
- StringReplace,MyAppName,MyAppName,<file_fullpath> ,%f_fileselected%,All
- ;ÌرðµÄ²ÎÊý
- IfInString,MyAppName,<clipon>
- {
- Clipboard:=f_fileselected
- StringReplace,MyAppName,MyAppName,<clipon>,,all
- }
- IfInString,MyAppName,<input>
- {
- Gui +LastFound +OwnDialogs +AlwaysOnTop
- InputBox, myinput,CandyInput,`n`n Please input your parameter: ,, 285, 175,,,,,
- if errorlevel
- ;ExitApp
- return
- Else
- StringReplace,MyAppName,MyAppName,<input>,%myinput%,all
- }
- IfInString,MyAppName,<hinput>
- {
- Gui +LastFound +OwnDialogs +AlwaysOnTop
- InputBox, myinput,CandyInput,`n`n Please input your parameter: ,Hide, 285, 175,,,,,
- if errorlevel
- ;ExitApp
- return
- Else
- StringReplace,MyAppName,MyAppName,<hinput>,%myinput%,all
- }
- IfInString,MyAppName,<select>
- {
- FileSelectFile, f_selectedname , , , Open a file,
- If f_selectedname <>
- {
- StringReplace,MyAppName,MyAppName,<select>,%f_selectedname%,all
- }
- Else
- {
- ;MsgBox,Canceled
- ;ExitApp
- return
- }
- }
- ;clear runn#
- clear=|||
- StringSplit,runn,clear,|
- ;Ìæ»»Íê³É£¬¾ÍÊÇÔËÐÐÁË
- StringSplit,runn,MyAppName,|
- If runn2=
- {
- If is_windowflag!=1 ;Èç¹ûÊÇwindows£¬ÄÇô¡°²Ù×÷¶ÔÏ󡱿ÉÒÔÖÿÕ
- runn2="%f_fileselected%"
- }
- ;MsgBox run %runn1%`, %runn2%`,%runn3%`,%runn4%
- if runn1="" and runn2=""
- return
- run,%runn1% %runn2%,%runn3%,%runn4% useerrorlevel
- ;1:³ÌÐò 2:Ä¿±ê 3:¹¤×÷Ŀ¼ 4:״̬
- ;ExitApp
- return
- }
-
-
-
-
-
-
- ;**************************************************************************************************************************
- ;by wannainshuyao@gmail.com
- ;**************************************************************************************************************************