Autohotkey 切换持久性工具提示

Autohotkey 切换持久性工具提示,autohotkey,Autohotkey,我想创建一些工具提示,根据MouseGetPos转储有关窗口的信息: ^Space=工具提示会打开和关闭,并跟随鼠标 ^+Space=工具提示暂时出现,然后消失 ^+空格=工具提示被切换并显示在屏幕的左下角 但是,工具提示不会在1和2中消失。3给出错误“未定义操作” 以下是我当前的代码: #注释标志// 切换:=假 ^空格:://切换工具提示并跟随鼠标 If(Toggle=False){ 切换:=真 #持久的 SetTimer,WatchCursor//如果我只有“WatchCursor”,没有

我想创建一些工具提示,根据
MouseGetPos
转储有关窗口的信息:

  • ^Space
    =工具提示会打开和关闭,并跟随鼠标
  • ^+Space
    =工具提示暂时出现,然后消失
  • ^+空格
    =工具提示被切换并显示在屏幕的左下角
  • 但是,工具提示不会在1和2中消失。3给出错误“未定义操作”

    以下是我当前的代码:

    #注释标志//
    切换:=假
    ^空格:://切换工具提示并跟随鼠标
    If(Toggle=False){
    切换:=真
    #持久的
    SetTimer,WatchCursor//如果我只有“WatchCursor”,没有“#Persistent”和“SetTimer”,我会得到一个“Action not defined”错误
    }Else If(Toggle=True){
    切换:=假
    工具提示
    } 
    返回
    ^+空格:://工具提示跟随鼠标,但在1秒后消失
    #持久的
    设置计时器,监视光标,1000
    返回
    ^!+空格:://工具提示出现在15113010处
    #持久的
    WatchCursor2//错误:此行不包含可识别的操作
    返回
    监视光标:
    鼠标,x,y,id,控件
    Wingtittle,标题,ahk_id%id%
    WingtClass,class,ahk_id%id%
    工具提示,-窗口信息--`n`tahk_id:`t%id%`n`tahk_类:`t%class%`n`tTitle:`t%title%`n`t控件:`t%control%`n`n--鼠标位置--`n`tX:`t%x%`n`tY:`t%y%
    监视游标2:
    鼠标,x,y,id,控件
    Wingtittle,标题,ahk_id%id%
    WingtClass,class,ahk_id%id%
    工具提示,-窗口信息--`n`tahk_id:`t%id%`n`tahk_类:`t%class%`n`tTitle:`t%title%`n`tControl:`t%control%`n`n--鼠标位置--`n`tX:`t%x%`n`tY:`t%y%,15113010
    
    下面的自动热键脚本应该为您提供确切的功能 你需要。我作出了一些修正和评论, 这应该可以解释你所经历的问题

    #CommentFlag //
    // #Persistent is not necessary for this script,
    // the presence of at least one hotkey,
    // is one way to make a script persistent
    
    Toggle := False
    
    // #p::Pause
    
    ^Space:: // Toggle the tooltip and follow the mouse
    
        If (Toggle = False) {
    
            Toggle := True
            vTickCount1 := A_TickCount
            SetTimer, WatchCursor
    
        } Else If (Toggle = True) {
    
            Toggle := False
            SetTimer, WatchCursor, Off
            // ToolTip
    
        }
    
    Return
    
    ^+Space:: // Tooltip follows mouse, but disappears after 1 second
    
        SetTimer, WatchCursor1, -1000 // negative to run once and then stop
        MouseGetPos, x, y, id, control
        WinGetTitle, title, ahk_id %id%
        WinGetClass, class, ahk_id %id%
        ToolTip, -- Window Info --`n`tahk_id:`t%id%`n`tahk_class:`t%class%`n`tTitle:`t%title%`n`tControl:`t%control%`n`n-- Mouse Pos --`n`tX:`t%x%`n`tY:`t%y%
    
    Return
    
    ^!+Space:: // Tooltip appears at 1511, 3010
    
    Gosub WatchCursor2
    
    Return
    
    WatchCursor1:
    ToolTip
    Return
    
    WatchCursor:
    MouseGetPos, x, y, id, control
    WinGetTitle, title, ahk_id %id%
    WinGetClass, class, ahk_id %id%
    ToolTip, -- Window Info --`n`tahk_id:`t%id%`n`tahk_class:`t%class%`n`tTitle:`t%title%`n`tControl:`t%control%`n`n-- Mouse Pos --`n`tX:`t%x%`n`tY:`t%y%
    
    // if (A_TickCount - vTickCount1 > 5000)
    // {
    // SetTimer, WatchCursor, Off
    // ToolTip
    // }
    Return // without this line the lines below in WatchCursor2 will also be triggered
    
    WatchCursor2:
    MouseGetPos, x, y, id, control
    WinGetTitle, title, ahk_id %id%
    WinGetClass, class, ahk_id %id%
    ToolTip, -- Window Info --`n`tahk_id:`t%id%`n`tahk_class:`t%class%`n`tTitle:`t%title%`n`tControl:`t%control%`n`n-- Mouse Pos --`n`tX:`t%x%`n`tY:`t%y%,1511,3010
    Return
    
    注意:这是一个非常好的脚本,使用起来非常愉快。

    注意:AutoHotkey的AccViewer是一个非常有用的脚本,用于检索有关windows和控件的信息,iWB2 Learner也可用于在Internet Explorer中检索有关web元素的信息。

    要跳转到标签,您需要
    goto
    。我现在意识到,我可以在脚本编辑器中使用Window Spy获取大部分信息。然而,我仍然想了解如何切换持久的工具提示。我认为@wOxxOm的意思是调用一次标签/子例程。这将解决未定义动作的问题。此外,每个子例程都应以
    返回值结束。在代码中,由于缺少返回,每次调用
    WatchCursor
    都会随后调用
    WatchCursor2
    。我不认为这是你想要的。@MCL那么你是说我需要在每个WatchCursor结束时返回?像
    工具提示一样,显示一些东西返回
    ?这很有道理,我不明白为什么所有的东西都在叫WatchCursor2。是的。后续子例程(也是热键例程)将跳转到下一个例程,直到遇到
    返回
    退出
    。感谢您的回复。您的代码解决了我面临的许多问题,对此我表示感谢。但是,它并没有解决我的主要问题:是否可以切换持久的工具提示?相反,它用计时器替换持久性:
    if(a_TickCount-vTickCount1>5000)SetTimer,WatchCursor,Off
    。谢谢你的回复。你不需要发布第二个答案,只需编辑你的第一个答案。好吧,我有两个想法,1.5票击败0.5票,我删除了第二个答案,编辑了第一个。非常酷。那剧本行得通。然而,我最初的问题没有得到解决。如果不可能切换一个持久性实体,那很好,只需在您的答案中解决它,那么我可以给您评分。