Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Autohotkey 用于将书签添加到特定文件夹的自动热键脚本_Autohotkey - Fatal编程技术网

Autohotkey 用于将书签添加到特定文件夹的自动热键脚本

Autohotkey 用于将书签添加到特定文件夹的自动热键脚本,autohotkey,Autohotkey,我正在使用Firefox,我正在寻找一个自动热键脚本,当我在一个特定文件夹中为一个页面添加书签并用一个键盘快捷键替换它时,它可以让我跳过整个点击序列 虽然我读过Autohotkey论坛上的论坛帖子,但在这里,我仍然不知道如何制作一个工作脚本,将页面书签简化为点击键盘快捷键和我要存储该页面的文件夹的首字母。使用KeyWait命令,我已经使它适用于单个文件夹,但不知道如何使它适用于任何可能用作书签文件夹名称的字母或数字。假设我有一个名为XXXX的文件夹,此脚本会在点击指定的快捷方式和字母x后将网页发

我正在使用Firefox,我正在寻找一个自动热键脚本,当我在一个特定文件夹中为一个页面添加书签并用一个键盘快捷键替换它时,它可以让我跳过整个点击序列

虽然我读过Autohotkey论坛上的论坛帖子,但在这里,我仍然不知道如何制作一个工作脚本,将页面书签简化为点击键盘快捷键和我要存储该页面的文件夹的首字母。使用KeyWait命令,我已经使它适用于单个文件夹,但不知道如何使它适用于任何可能用作书签文件夹名称的字母或数字。假设我有一个名为XXXX的文件夹,此脚本会在点击指定的快捷方式和字母x后将网页发送到XXXX文件夹(需要使用鼠标单击命令在书签对话框窗格中将窗口与文件夹对焦):

我不知道如何使这个脚本适用于任何字母或数字,而不仅仅是单个字母或数字。这个脚本的另一个大问题是它会阻塞键盘,直到我按下X键。如果我已经为该页面添加了书签,点击escape删除书签窗格将阻止键盘,只有在重新运行自动热键脚本时,我才能取消阻止

我也尝试过使用Input命令作为Autohotkey论坛页面建议的贡献者,但它也不起作用,因为我不理解Input命令是如何工作的。我确实用KeyWait为一封信编写了上面的脚本,但这是我能做的最好的了。此脚本还会阻止键盘,直到击中字母:

!+^w::
Send,^d
MouseClick,Left,864,304
Sleep,400
Input, Character, L1
If Character = t
Send, t
Sleep,400
Send,^{Enter}
return

希望有人能帮助我,这样可以方便地简化Firefox中的书签过程。

我有个好主意。这将打开“添加书签”对话框,将您导航到文件夹选择部分并展开所有文件夹。 您只需输入文件夹名称(或其一部分),它就会自动被选中。完成后,只需按enter键

!+^w::                      ;Hotkey: Ctrl+Alt+Shift+w
    Send, ^d                ;send Ctrl+d to open the add-bookmark dialog
    Sleep, 500              ;wait for the dialog to open
    Send, {Tab}{Tab}{Enter} ;navigate into the folder selection
    Sleep, 300              ;wait to make sure we are there
    Send,{Home}             ;select the first item in the list
                            ;The following line should expand all the folders so that you can just type the folders name to search for it
    Loop, 100 {             ;Increase the number if it doesn't expand all folders
        SendInput, {Right}{Down} ;expand folders
    }
    Send, {Home}            ;navigate to the first item in the list again
    Input, L, V L1 T2       ;wait until you start typing a folder name (if you just wait 2 seconds, the bookmark won't be created)
    If (ErrorLevel =  "Timeout") {
        Send, {Tab 5}       ;press tab 5 times to navigate to the cancel button
        Send, {Enter}       ;cancel the bookmark
        Return              ;end of the hotkey
    }
    Loop {                  ;wait until you haven't typed a new letter for 0.4 seconds
        Input, L, V L1 T0.4
        If (ErrorLevel =  "Timeout")
            Break
    }
    Send, {Tab 4}           ;press tab 4 times to navigate to the enter button
    Send, {Enter}           ;save the bookmark
Return

我有个好主意。这将打开“添加书签”对话框,将您导航到文件夹选择部分并展开所有文件夹。 您只需输入文件夹名称(或其一部分),它就会自动被选中。完成后,只需按enter键

!+^w::                      ;Hotkey: Ctrl+Alt+Shift+w
    Send, ^d                ;send Ctrl+d to open the add-bookmark dialog
    Sleep, 500              ;wait for the dialog to open
    Send, {Tab}{Tab}{Enter} ;navigate into the folder selection
    Sleep, 300              ;wait to make sure we are there
    Send,{Home}             ;select the first item in the list
                            ;The following line should expand all the folders so that you can just type the folders name to search for it
    Loop, 100 {             ;Increase the number if it doesn't expand all folders
        SendInput, {Right}{Down} ;expand folders
    }
    Send, {Home}            ;navigate to the first item in the list again
    Input, L, V L1 T2       ;wait until you start typing a folder name (if you just wait 2 seconds, the bookmark won't be created)
    If (ErrorLevel =  "Timeout") {
        Send, {Tab 5}       ;press tab 5 times to navigate to the cancel button
        Send, {Enter}       ;cancel the bookmark
        Return              ;end of the hotkey
    }
    Loop {                  ;wait until you haven't typed a new letter for 0.4 seconds
        Input, L, V L1 T0.4
        If (ErrorLevel =  "Timeout")
            Break
    }
    Send, {Tab 4}           ;press tab 4 times to navigate to the enter button
    Send, {Enter}           ;save the bookmark
Return
我的变种。 按f1键在文件夹test1中创建书签。 按f2键在文件夹test2中创建书签

SetBatchLines, -1
Folders := {F1: "test1", F2: "test2"}
#IfWinActive, ahk_class MozillaWindowClass
F1::
F2::
Folder := Folders[A_ThisHotkey]
Send, ^d
AccFirefox := Acc_ObjectFromWindow(WinExist("ahk_class MozillaWindowClass"))
AccElem := SearchElement(AccFirefox, ROLE_SYSTEM_LISTITEM := 0x22, Folder, "")
AccElem.accDoDefaultAction(0)
sleep 100
Send {Enter}
msgbox done
return
#IfWinActive

SearchElement(ParentElement, params*)
{
   found := 1
   for k, v in params  {
      (k = 1 && ParentElement.accRole(0) != v && found := "")
      (k = 2 && ParentElement.accName(0) != v && found := "")
      (k = 3 && ParentElement.accValue(0) != v && found := "")
   }
   if found
      Return ParentElement

   for k, v in Acc_Children(ParentElement)
      if obj := SearchElement(v, params*)
         Return obj
}

Acc_Init()
{
    Static  h
    If Not  h
        h:=DllCall("LoadLibrary","Str","oleacc","Ptr")
}

Acc_ObjectFromWindow(hWnd, idObject = 0)
{
    Acc_Init()
    If  DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject&=0xFFFFFFFF, "Ptr", -VarSetCapacity(IID,16)+NumPut(idObject==0xFFFFFFF0?0x46000000000000C0:0x719B3800AA000C81,NumPut(idObject==0xFFFFFFF0?0x0000000000020400:0x11CF3C3D618736E0,IID,"Int64"),"Int64"), "Ptr*", pacc)=0
    Return  ComObjEnwrap(9,pacc,1)
}

Acc_Query(Acc) { ; thanks Lexikos - www.autohotkey.com/forum/viewtopic.php?t=81731&p=509530#509530
    try return ComObj(9, ComObjQuery(Acc,"{618736e0-3c3d-11cf-810c-00aa00389b71}"), 1)
}

Acc_Error(p="") {
    static setting:=0
    return p=""?setting:setting:=p
}

Acc_Children(Acc) {
    if ComObjType(Acc,"Name") != "IAccessible"
        ErrorLevel := "Invalid IAccessible Object"
    else {
        Acc_Init(), cChildren:=Acc.accChildCount, Children:=[]
        if DllCall("oleacc\AccessibleChildren", "Ptr",ComObjValue(Acc), "Int",0, "Int",cChildren, "Ptr",VarSetCapacity(varChildren,cChildren*(8+2*A_PtrSize),0)*0+&varChildren, "Int*",cChildren)=0 {
            Loop %cChildren%
                i:=(A_Index-1)*(A_PtrSize*2+8)+8, child:=NumGet(varChildren,i), Children.Insert(NumGet(varChildren,i-8)=9?Acc_Query(child):child), NumGet(varChildren,i-8)=9?ObjRelease(child):
            return Children.MaxIndex()?Children:
        } else
            ErrorLevel := "AccessibleChildren DllCall Failed"
    }
    if Acc_Error()
        throw Exception(ErrorLevel,-1)
}
我的变种。 按f1键在文件夹test1中创建书签。 按f2键在文件夹test2中创建书签

SetBatchLines, -1
Folders := {F1: "test1", F2: "test2"}
#IfWinActive, ahk_class MozillaWindowClass
F1::
F2::
Folder := Folders[A_ThisHotkey]
Send, ^d
AccFirefox := Acc_ObjectFromWindow(WinExist("ahk_class MozillaWindowClass"))
AccElem := SearchElement(AccFirefox, ROLE_SYSTEM_LISTITEM := 0x22, Folder, "")
AccElem.accDoDefaultAction(0)
sleep 100
Send {Enter}
msgbox done
return
#IfWinActive

SearchElement(ParentElement, params*)
{
   found := 1
   for k, v in params  {
      (k = 1 && ParentElement.accRole(0) != v && found := "")
      (k = 2 && ParentElement.accName(0) != v && found := "")
      (k = 3 && ParentElement.accValue(0) != v && found := "")
   }
   if found
      Return ParentElement

   for k, v in Acc_Children(ParentElement)
      if obj := SearchElement(v, params*)
         Return obj
}

Acc_Init()
{
    Static  h
    If Not  h
        h:=DllCall("LoadLibrary","Str","oleacc","Ptr")
}

Acc_ObjectFromWindow(hWnd, idObject = 0)
{
    Acc_Init()
    If  DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject&=0xFFFFFFFF, "Ptr", -VarSetCapacity(IID,16)+NumPut(idObject==0xFFFFFFF0?0x46000000000000C0:0x719B3800AA000C81,NumPut(idObject==0xFFFFFFF0?0x0000000000020400:0x11CF3C3D618736E0,IID,"Int64"),"Int64"), "Ptr*", pacc)=0
    Return  ComObjEnwrap(9,pacc,1)
}

Acc_Query(Acc) { ; thanks Lexikos - www.autohotkey.com/forum/viewtopic.php?t=81731&p=509530#509530
    try return ComObj(9, ComObjQuery(Acc,"{618736e0-3c3d-11cf-810c-00aa00389b71}"), 1)
}

Acc_Error(p="") {
    static setting:=0
    return p=""?setting:setting:=p
}

Acc_Children(Acc) {
    if ComObjType(Acc,"Name") != "IAccessible"
        ErrorLevel := "Invalid IAccessible Object"
    else {
        Acc_Init(), cChildren:=Acc.accChildCount, Children:=[]
        if DllCall("oleacc\AccessibleChildren", "Ptr",ComObjValue(Acc), "Int",0, "Int",cChildren, "Ptr",VarSetCapacity(varChildren,cChildren*(8+2*A_PtrSize),0)*0+&varChildren, "Int*",cChildren)=0 {
            Loop %cChildren%
                i:=(A_Index-1)*(A_PtrSize*2+8)+8, child:=NumGet(varChildren,i), Children.Insert(NumGet(varChildren,i-8)=9?Acc_Query(child):child), NumGet(varChildren,i-8)=9?ObjRelease(child):
            return Children.MaxIndex()?Children:
        } else
            ErrorLevel := "AccessibleChildren DllCall Failed"
    }
    if Acc_Error()
        throw Exception(ErrorLevel,-1)
}

你的第二种方法对我来说很好。。。?尝试用简单的
send%character%
替换
如果character=t
/
send,t
。如果希望
Input
不阻止发送的键,请使用
V
选项(请参阅ahkscript文档->Input)您好,谢谢您的回答。输入命令是否像KeyWait一样工作?我希望脚本在等待字符输入后执行其余代码。在书签对话框窗口中确认书签是通过Ctrl+Enter来完成的,我想通过使用脚本来避免该快捷方式,该脚本将为我自动执行书签。是的,
input
“暂停”脚本,如
keyWait
。您声明了
L1
,因此在第一次按键后,它将立即继续。打印的信件将保存到
字符中
。您的第二种方法对我来说很好。。。?尝试用简单的
send%character%
替换
如果character=t
/
send,t
。如果希望
Input
不阻止发送的键,请使用
V
选项(请参阅ahkscript文档->Input)您好,谢谢您的回答。输入命令是否像KeyWait一样工作?我希望脚本在等待字符输入后执行其余代码。在书签对话框窗口中确认书签是通过Ctrl+Enter来完成的,我想通过使用脚本来避免该快捷方式,该脚本将为我自动执行书签。是的,
input
“暂停”脚本,如
keyWait
。您声明了
L1
,因此在第一次按键后,它将立即继续。打印的信件将保存到
字符中
。您好,谢谢您的帮助!我想摆脱“进入”。我用MouseClick命令使文件夹窗口聚焦,我所需要做的就是键入字母并按Enter键。我不需要按键等待或输入。我已经将书签简化为一个快捷方式,一个字母,然后按Enter键。这听起来可能不必要,但我做了很多书签,我想让它尽可能短,这意味着我想避免点击回车键,这就是为什么我需要键盘等待或输入功能,以自动完成确认我输入的字母的最后一步。好的,但这意味着每个文件夹都必须以不同的字母开头。你真的想要吗?@RejlanGivens我刚刚有了一个想法并编辑了剧本。脚本现在将等待,直到您停止键入文件夹名称0.4秒,然后它将自动为您保存书签。这对我来说真的很棒,你觉得怎么样?很有魅力谢谢你!当我不确认书签时,我也不会对被阻止的键盘有任何问题,尽管在这种情况下,快捷键在再次使用键盘之前不会起作用,这其实根本不是问题。(例如,我要保存的书签已经在我的书签中,我点击escape或在另一个页面上单击鼠标,在这种情况下,如果我想为另一个页面添加书签,快捷方式将不起作用,直到我再次激活键盘,开始键入任何内容,出于某种原因再次启用快捷方式)。再次非常感谢你!一旦我获得论坛在这里投票所需的15个声誉,我将更新你的脚本,作为其他人的信息,他们可能会发现这个功能和我一样有用。嗨,福林,谢谢你的帮助!我想摆脱“进入”。我用鼠标来聚焦文件夹窗口