自编aJump跳转小工具(含源码)

1、这是我从ago中剥离出来的一个纯粹文件夹跳转的功能,类似的软件也比较多。在资源管理器/打开保存对话框中呼出菜单实现快速目录跳转。功能单一,对win10以下的系统未测试。测试环境:WIN11-X64,在win10的x64上应该没问题,再低的windows版本未测试。如果需要x86系统可以自己源码编译即可。

2、呼出方式有两种:
 a、双击热键,默认为shift键,可以设置为其他键,建议设置为不常用或不与其他程序冲突的热键;
如AppsKey键(就是windows键盘不常用的菜单键)
b、双击资源管理器或打开对话框窗口中的的无控件位置呼出菜单。(控件位置的意思是这个位置没有列表框没有按钮没有文字空白窗体),自行点击体会。

另外在打开文件对话框的文件名称编辑框(edit1)双击也可以呼出菜单(此仅适合打开/保存文件对话框界面)

3、支持win11的terminal窗口的切换(含cmd和powershell),windows10的cmd.exe未测试。

4、在其他非资源管理器窗口或者打开对话框窗口呼出菜单点击则就是直接开资源管理器窗口。

5、目前测试对acad.exe的打开对话框无效。

下载地址:

蓝奏云:https://ilaoyao.lanzouo.com/b0177fy5a

(提取码:9999

太简陋,没图片。程序源码如下:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Persistent	;保持后台运行
#SingleInstance FORCE ;单实例运行模式
#NoTrayIcon  ;不显示图标,后面需要用Menu, Tray, Icon重新显示托盘图标
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%
SetWorkingDir %A_WorkingDir%  ; Ensures a consistent starting directory.
SetBatchLines -1
ListLines Off
DetectHiddenWindows, on ;检测隐藏窗口
CoordMode, menu ;设置菜单为全屏幕坐标


;****************************************************************************
;*****************************变量即配置数据部分-开始*******************
;****************************************************************************

;--------------------------配置文件路径及名称-------------------------------
global g_config:=A_WorkingDir . "\config.ini" ;定义config文件的位置
global thisexefile:=SubStr(A_ScriptFullPath,1,StrLen(A_ScriptFullPath)-4)  ".exe"

global g_hotkeyname
IniRead , g_hotkeyname2 , %g_config% , general , hotkeyname2

global  g_hotkeyname2
if (g_hotkeyname2 = "ERROR" ) or   (g_hotkeyname2 = "" ) 
{
	g_hotkeyname2:="~SHIFT"
}

Hotkey, % g_hotkeyname2, hotkeyopen_MainWindowGUI, on ;热键启动主窗口

global gnPressCount := 0 ;判断鼠标双击指标
global g_version:="Ver 0.0.1"
global g_window_title :="aJump" ;输入运行框窗口标题
global g_aJump_resdll:=thisexefile ;帮助对话框默认图标

;--------------------------菜单图标-------------------------------
IniRead , g_menuiconsize , %g_config% , general , menuiconsize 
    if ( g_menuiconsize = "ERROR") or ( g_menuiconsize = "")  
    {
        g_menuiconsize:=24 ;如果未读取到,默认定义为24
    }
;--------------------------菜单图标-------------------------------


;****************************************************************************
;*****************************变量即配置数据部分-结束****************************
;****************************************************************************


;------------------------命令,文件夹和快速文本速度读取----------------------------
;V1.4版本修改,首先读取s_cmd和quickfolder以及快速文本的内容生成数组,后面统一使用,减少
;变量内存占据量

hotstring("reset")

;~ global cmd_arr:=Object()
global folder_arr:=Object()
;~ global quicktxt_arr:=object()

      
;3、读取快速文件夹跳转
					IniRead, s0_temp2, %g_config%,  quick_folder ;读取程序运行区域全部内容
                    loop,parse,s0_temp2,"`n"
                    {
						
						;开始需要清空变量,防止循环中碰到空值时该变量会继续使用上一次的内容值。
						s0_temp2_1=
						s0_temp2_2=
						s0_temp2_3=
						hotstring_folder_temp1=
						hotstring_folder_temp2=
						hotstring_folder_temp3=
						hotstring_folder_temp_A1=
						hotstring_folder_temp_A2=
						 
					
                        s0_temp2_1:=SubStr(A_LoopField,1,instr(A_LoopField,"=")-1) ;获取等号左边 						
                        s0_temp2_2:=SubStr(A_LoopField,instr(A_LoopField,"=")+1) ;获取等号右边                        
                        StringSplit, hotstring_folder_temp, % s0_temp2_2,"|"
						
						folder_arr[a_index,1]:=s0_temp2_1 ;菜单显示名称						
						folder_arr[a_index,2]:=hotstring_folder_temp1 ;文件夹路径
						

						if hotstring_folder_temp2
						{
							StringSplit, hotstring_folder_temp_A, % hotstring_folder_temp2 , "`,"							
							folder_arr[a_index,3]:=hotstring_folder_temp_A1	;自定义图标名称,
							folder_arr[a_index,4]:=hotstring_folder_temp_A2	;图标序号,
							
							if (hotstring_folder_temp_A2="") ;如果没有设定图标序号,默认取1
								folder_arr[a_index,4]:="1"
						}
						else
						{
							folder_arr[a_index,3]=get_file_icon(hotstring_folder_temp1) ;未自定图标,采用默认图标
							folder_arr[a_index,4]:=""	;图标序号为空,
						}

					;~ msgbox,,,% folder_arr[a_index,1] "`n"  folder_arr[a_index,2] "`n"  folder_arr[a_index,3] "`n"  folder_arr[a_index,4],2 
					}
					;清空变量
						s0_temp2=
						s0_temp2_1=
						s0_temp2_2=
						hotstring_folder_temp1=
						hotstring_folder_temp2=
						hotstring_folder_temp_A1=
						hotstring_folder_temp_A2=
						

;------------------------命令,文件夹和快速文本数组读取---------------------------- 2020.11.21 三个数组配置成功,写到这里暂时结束

gosub, createquickmenu_noshow
gosub, create_tray_menu
EmptyMem()
return



create_tray_menu:
Menu, tray, UseErrorLevel ;菜单错误时避免跳出对话框中止进程的操作,该设置影响全局所有菜单,不仅仅是tray菜单。
Menu, tray, NoStandard ;取消标准的tray菜单
Menu, tray, icon
menu, tray, icon, %g_aJump_resdll% , 1 ;%g_trayicon_index% ,icongroup的15序号;

menu, tray, add, 关于aJump, aboutme
menu, tray, icon, 关于aJump, %g_aJump_resdll% , 2
menu, tray, add, 退出aJump,exitme
menu, tray, icon, 退出aJump, %g_aJump_resdll% , 3
return
	;--------------------------------------------------------------传统菜单模式---------------------------------------
	
	
	
	
;*********************
;生成关于的窗体,但是不显示。该窗体已经被设置窗口代替,
;v2.2版本修改为启动不生成,按需显示
;*********************
aboutme: 
IfWinExist, ahk_id %AboutID%
	GUI, HelpWindow:destroy
	
    gui, HelpWindow:-Caption  +hwndAboutID ;-DPIScale
    gui, HelpWindow:color, 2B2B2B
	GUI, HelpWindow:MARGIN,30,30
    GUI, HelpWindow:add, picture,   x40 y60 w96 h-1 icon1 vaboutdonate, % g_aJump_resdll
	
	GUI, HelpWindow:font , s16 Q5  Bold cd2d2d2 , 微软雅黑
    GUI, HelpWindow:add, text,x+40 y20, % "About"


    GUI, HelpWindow:font , s10 norm
    GUI, HelpWindow:add, text, xp y+10,
(
1、这是一个简单的文件夹跳转功能的菜单软件。在资源管理器/打开保存对话框中
呼出菜单实现快速目录跳转。功能单一,对win10以下的系统未测试

2、呼出方式有两种:
 a、双击热键,默认为shift键,可以设置为其他键,建议设置为不常用或不与其他程序冲突的热键;
如AppsKey键(就是windows键盘不常用的菜单键)
b、双击资源管理器或打开对话框窗口中的的无控件位置呼出菜单。
无控件位置的意思是这个位置没有列表框没有按钮没有文字空白窗体)
3、支持win11的terminal窗口的切换(含cmd和powershell)
4、在其他非资源管理器窗口或者打开对话框窗口呼出菜单则就是直接开资源管理器窗口。

有问题请到 http://www.ilaoyao.cn/?list-39.html 页面留言。
作者:ilaoyao 
版本:X64 Ver 0.0.1 


)


    GUI, HelpWindow:font , s10 Q5 W300 normal cE0E0E0 
    GUI, HelpWindow:add, text, x15 y15 BackgroundTrans center gcloseabout, % "❌"    

    Gui, HelpWindow:show, hide autosize center, % "about ajump"    
    WinGetPos, , , w_temp, h_temp, % "about ajump" ;获得当前窗体的坐标xy(本例省略)以及宽度高度等数据。	
	
	winset, Region, % "0-0 w" w_temp " h" h_temp " R5-5", % "about ajump"
	winset, transparent, 235,  % "about ajump"
	winset,redraw,,% "about ajump" 

	Gui, HelpWindow:show
    
	;~ hotkey,esc,on ;每次窗体显示的时候激活esc按钮热键
    EmptyMem()
    return
;*********************
;生成关于的窗体。
;*********************

closeabout:
gui, HelpWindow:destroy ;销毁帮助窗口
EmptyMem()
return

exitme:
exitapp
return
	
createquickmenu_noshow:	
		menu,  quickmenu, UseErrorLevel
		menu , quickmenu, deleteall ;这行命令添加可以防止每弹出一次菜单编增加一个分格线的bug,原因不明。官方的帮助文件也没找到。					
		loop, % folder_arr._maxindex()
		{
			if (folder_arr[a_index,1]="X")
			{
				menu, quickmenu,add
				continue
			}
				menu, quickmenu, add, % folder_arr[a_index,1], menu_path_run_new
				menu, quickmenu, icon, % folder_arr[a_index,1], % folder_arr[a_index,3], % folder_arr[a_index,4], % g_menuiconsize
		}

					menustatus:="finished"

return

;*************************
;鼠标双击事件
;*************************
~LButton:: 
{
		gnPressCount += 1
        if gnPressCount = 1
			SetTimer, ProcSubroutine, 300 ;400为间隔时间,ms单位
return
}


;定时程序
ProcSubroutine:
{
                
        ; 在计时器事件触发时,需要将其关掉
        SetTimer, ProcSubroutine, Off
        If gnPressCount = 2
        {
	    
			MouseGetPos,,,A_WIN_id2,a_ctrl_name2
			WinGetClass, a_win_class2, ahk_id %a_win_id2%
			if( a_win_class2="#32770") 
			{
				if (a_ctrl_name2="") or (a_ctrl_name2="Edit1"){ ;只能在左侧
					gosub, createquickmenu_noshow
					if(menustatus="finished"){
						menu , quickmenu , show
						menu , quickmenu, deleteall ;这行命令添加可以防止每弹出一次菜单编增加一个分格线的bug,原因不明。官方的帮助文件也没找到。
					}
				}
			}		
        }
        ; 在结束后,还需要将鼠标右键的按键次数置为0,以方便下次使用
		gnPressCount := 0
        Return
}





;V1.4版本中的菜单跳转
menu_path_run_new:
    newpath :=folder_arr[a_thismenuitempos,2]
     
    MouseGetPos,,,A_WIN_id
    WinGetClass, a_win_class, ahk_id %a_win_id%


    If (a_win_class="CabinetWClass") ;表示当前窗口为活动窗口
    {
        if (newpath="::{20d04fe0-3aea-1069-a2d8-08002b30309d}") ;我的电脑
        {
            ShellNavigate("c:\")
            sleep,10
            send !{up}
        }
        else
        {         
            ShellNavigate(newpath)
        }
    }
  
    else if winactive("ahk_class #32770") ;#32770表示打开文件对话框 ,对应控件为static3,
    {
			
				ControlGetText, w_Edit1Text,edit1, A
				ControlFocus, edit1 , A 
				ControlSetText, edit1, %newpath%, A
				ControlSend, edit1,{Enter}, A
				ControlSetText, edit1, %w_Edit1Text%, A
				sleep, 10
            EmptyMem()
            return
    }


    else if winactive("ahk_class ConsoleWindowClass") ;表示CMD命令行
    {

        if (newpath="::{20d04fe0-3aea-1069-a2d8-08002b30309d}")
            newpath :="c:\"
        
        Clipboard :="cd /d """ . newpath . """" ;加双引号防止路径中含空格
        ClipWait
        ;click right ;鼠标右键黏贴
        send {click right}{enter}
        sleep, 100
    }

	
	else if winactive("ahk_class CASCADIA_HOSTING_WINDOW_CLASS")  ;表示terminal命令行 
      {		
			wingettitle, actitle2, A					
        if (newpath="::{20d04fe0-3aea-1069-a2d8-08002b30309d}")
            newpath :="c:\"
		
				 if instr( actitle2,  "powershell" ) 
				{
						Clipboard :="cd  """ . newpath . """" ;加双引号防止路径中含空格
				}

				else if instr( actitle2,  "command prompt" )  or  instr( actitle2,  "cmd" ) 
				{
					 Clipboard :="cd /d """ . newpath . """" ;加双引号防止路径中含空格
				 }
		 
        ClipWait
        send {click right}{enter}
		 sleep, 10
    }
	
    else ;表示为其他窗口,则运行程序 
    {
        
        w1:= ComObjCreate("Shell.Application")
        w1.open(newpath)
    }  
        
		newpath=
		A_WIN_id=
		A_WIN_class=
       
        EmptyMem()
        return
		
;***************************
;热键菜单-文件夹跳转点击事件-结束
;***************************

;laoyao++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


;***********文件夹跳转函数,V2.7版本开始使用******
;使用方法: ShellNavigate("d:\123")这样就可以了。
ShellNavigate(sPath, bExplore=False, hWnd=0)
{
   shell  :=   ComObjCreate("Shell.Application")
   If   hWnd||(hWnd:=WinExist("ahk_class CabinetWClass"))||(hWnd:=WinExist("ahk_class ExploreWClass"))
   {
      Loop, % shell.Windows.Count
        If ( (win := shell.Windows.Item(A_Index-1)).hWnd = hWnd )
          Break
      win.Navigate2(sPath)
   }
   Else bExplore ? shell.Explore(sPath) : shell.Open(sPath)
}
;***********文件夹跳转函数,V2.7版本开始使用******


;laoyao++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



;***********************
;双击激活菜单显示-改标签跳转
;**********************
hotkeyopen_MainWindowGUI:
;~LALT::
	
    if (A_PriorHotkey <> g_hotkeyname2 or A_TimeSincePriorHotkey > 350 )
    {
        ;~ msgbox, % "Too much time between presses, so this isn't a double-press."
        KeyWait, % g_hotkeyname2
        EmptyMem()
        return
    }
					gosub, createquickmenu_noshow
					if(menustatus="finished"){
						menu , quickmenu , show
						menu , quickmenu, deleteall ;这行命令添加可以防止每弹出一次菜单编增加一个分格线的bug,原因不明。官方的帮助文件也没找到。
					}
        EmptyMem()
        return


EmptyMem(){
    pid:=() ? DllCall("GetCurrentProcessId") : pid
    h:=DllCall("OpenProcess", "UInt", 0x001F0FFF, "Int", 0, "Int", pid)
    DllCall("SetProcessWorkingSetSize", "UInt", h, "Int", -1, "Int", -1)
    DllCall("CloseHandle", "Int", h)
}


Explorer_GetPath(hwnd="")
{
	if !(window := Explorer_GetWindow(hwnd))
		return ErrorLevel := "ERROR"
	if (window="desktop")
		return A_Desktop
	path := window.LocationURL
	path := RegExReplace(path, "ftp://.*@","ftp://")
	StringReplace, path, path, file:///
	StringReplace, path, path, /, \, All 
	; thanks to polyethene
	Loop
		If RegExMatch(path, "i)(?<=%)[\da-f]{1,2}", hex)
			StringReplace, path, path, `%%hex%, % Chr("0x" . hex), All
		Else Break
	return path
}

Explorer_GetAll(hwnd="")
{
	return Explorer_Get(hwnd)
}


Explorer_GetSelected(hwnd="")
{
	return Explorer_Get(hwnd,true)
}

Explorer_GetWindow(hwnd="")
{
	; thanks to jethrow for some pointers here
    WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
    WinGetClass class, ahk_id %hwnd%

	if (process!="explorer.exe")
		return
	if (class ~= "(Cabinet|Explore)WClass")
	{
		for window in ComObjCreate("Shell.Application").Windows
			if (window.hwnd==hwnd)
				return window
	}
	else if (class ~= "Progman|WorkerW") 
		return "desktop" ; desktop found
}

Explorer_Get(hwnd="",selection=false)
{
	if !(window := Explorer_GetWindow(hwnd))
		return ErrorLevel := "ERROR"
	if (window="desktop")
	{
		ControlGet, hwWindow, HWND,, SysListView321, ahk_class Progman
		if !hwWindow ; #D mode
			ControlGet, hwWindow, HWND,, SysListView321, A
		ControlGet, files, List, % ( selection ? "Selected":"") "Col1",,ahk_id %hwWindow%
		base := SubStr(A_Desktop,0,1)=="\" ? SubStr(A_Desktop,1,-1) : A_Desktop
		Loop, Parse, files, `n, `r
		{
			path := base "\" A_LoopField
			IfExist %path% ; ignore special icons like Computer (at least for now)
				ret .= path "`n"
		}
	}
	else
	{
		if selection
			collection := window.document.SelectedItems
		else
			collection := window.document.Folder.Items
		for item in collection
			ret .= item.path "`n"
	}
	return Trim(ret,"`n")
}

get_file_icon(this_fullpathname)
{
    VarSetCapacity(fileinfo, fisize := A_PtrSize + 688)
    ;~ ; 获取文件的图标.
    if DllCall("c:\windows\system32\shell32\SHGetFileInfoW", "wstr", this_fullpathname, "uint", 0, "ptr", &fileinfo, "uint", fisize, "uint", 0x100)
    {
        g_hicon_temp := NumGet(fileinfo, 0, "ptr")
        g_hicon = HICON:%g_hicon_temp%  
    }
return g_hicon
}


给TA捐赠
共{{data.count}}人
人已捐赠
其他

AHK 将win11的时间电池信息置顶显示

2022-2-20 3:32:12

应用案例

AHK 通过公开的天气API获取json数据并读取

2022-2-21 10:14:46

6 条回复 A文章作者 M管理员
  1. ahkjoo

    下载了运行看了一下,双击之后是回到上一目录. 这个热键确实和listary冲突了,不过你的想法不错,后续我跟进,希望持续更新,多谢!

    • ilaoyao

      双击返回上一层这个应该是另外那个软件ago才有的,这个代码里面双击只会在控件是否为edit1或者是无控件区域才会跳出菜单,而且应该没有返回上一层的代码的。
      冲突是可能的,毕竟剩余并且不影响正常操作的方式就那么点。?

  2. ahkjoo

    再看了一下,这个配置和相关思路值得学习,有时间我在你基础上改一下,多谢

  3. ahkjoo

    这个代码好像不全?

    • ilaoyao

      这个代码是完整的代码,我编译就是这个代码编译的。

  4. 望山观海

    1、代码没问题,但是缺少config文件,所以按热键显示不出来。 2、menu , quickmenu, deleteall ;这行命令添加可以防止每弹出一次菜单编增加一个分格线的bug,原因不明。官方的帮助文件也没找到。(这点我研究了很久,下面解释原因和另一种显示menu方法) 重复显示menu会显示bug分割线,这里要解释一下原因:点击Menu后它是隐藏了menu,而不是销毁了menu。 把menu show的命令放在标签里,第二次跳转这个标签menu,又进行了add的话就重复显示了所以会显示bug分割线(分割线下面其实就是重复添加的菜单项目)。 解决方法: 1、做deleteall全部删除的命令,第二次跳转此标签显示menu就不会重复显示。 另一种显示menu方法是: 1、menu的标签只做add的命令。(直接放在自动执行段就行,或者用gosub,遇到show命令才会显示) 2、另作一个show标签来显示menu

个人中心
购物车
优惠劵
有新私信 私信列表
搜索