显示自动热键热键列表 [英] Displaying List of AutoHotkey Hotkeys

查看:127
本文介绍了显示自动热键热键列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了包含许多热键的脚本(一般结构如下).我想创建另一个按钮,当按下该按钮时,将在一个漂亮的格式化表格中显示所有热键及其对应描述的列表.

I’ve written script that contains numerous hotkeys (general structure is as below). I would like to create another one that when pressed displays a list of all of the hotkeys and their corresponding descriptions that the script contains in a nice, formatted table.

由于AutoHotkey的输出仅限于消息框,因此格式和显示都很麻烦,但是可以.更麻烦的是获取热键和相应的说明.

The formatting and display are tenuous since AutoHotkey’s output is limited to message-boxes, but possible. More problematic is getting the hotkeys and corresponding descriptions.

所有热键都使用不同的参数调用相同的函数.我考虑过在函数中添加一个变量,以便根据值的不同,该函数要么在由普通热键触发时执行普通功能,要么从特殊显示热键触发时生成字符串或其他内容.

The hotkeys all call the same function with different arguments. I considered adding a variable to the function so that depending on the value, the function either performs the normal function when triggered by the normal hotkeys, or builds a string or something when triggered from the special display hotkey.

我完全找不到一种以编程方式访问脚本的热键的方法.我检查了文档,似乎没有任何A_变量可用于此目的,Hotkey命令也不适合自己使用(它可用于测试热键是否存在,但可以循环浏览)无数的组合是充其量乏味).

I cannot figure out a way to programmatically access the script’s hotkeys at all. I checked the docs and there don’t seem to be any A_ variables that can be used for this purpose, nor does the Hotkey command lend itself well (it can be used to test if a hotkey exists, but looping through the innumerable combinations is, at best, tedious).

尝试失败:

  • 我尝试了使用Elliot的建议来解析脚本本身(用%A_ScriptFullPath%替换路径,虽然它对原始脚本有效,但在编译脚本时却不起作用
  • 我尝试将脚本的整个热键部分分配给变量作为延续部分,然后解析该变量并使用Hotkey命令创建热键.这一直很好,直到最后一部分为止,因为 Hotkey 命令不能将任意命令作为目标,并且需要现有的标签.
  • ListHotkeys命令不适用,因为它仅在控制窗口中将热键显示为纯文本.
  • I tried using Elliot’s suggestion of parsing the script itself (replacing the path with %A_ScriptFullPath%, and while it does work for a raw script, it does not when the script is compiled
  • I tried assigning the entire hotkey section of the script to a variable as a continuation section and then parsing the variable and creating hotkeys using the Hotkey command. This worked well right up until the last part because the Hotkey command cannot take arbitrary commands as the destination and requires existing labels.
  • The ListHotkeys command is not applicable because it only displays the hotkeys as plain text in the control window.

有人知道我如何显示热键及其对应的参数或注释的列表吗?

Does anyone know how I can display a list of the hotkeys and either their corresponding arguments or comments?


示例脚本:


Example script:

SomeFunc(foobar)
{
  MsgBox %foobar%
}

         !^#A::SomeFunc("a") ; blah
 ^+NumpadMult::SomeFunc("c") ; blivet
        ^+!#`::SomeFunc("b") ; baz
      ^#Space::SomeFunc("d") ; ermahgerd
 …

示例所需的输出":

C+A+  W+ A   a    | C+ S+   NumpadMult  b
------------------+----------------------
C+A+S+W+ `   c    | C+   W+ Space       d

Ctrl Alt Shift Win  Key         Action
-----------------------------------------
 ×    ×         ×   A           blah
 ×        ×         NumpadMult  baz
 ×    ×   ×     ×   `           blivet
 ×              ×   Space       ermahgerd

etc.

推荐答案

我找到了解决方案.它不是完美的(或理想的),希望将来会提供适当的内置方法,但它可以很好(足够)并且适用于原始脚本和编译脚本.

I found a solution. It is not perfect (or ideal), and hopefully a proper, built-in method will become available in the future, but it works well (enough) and for raw and compiled scripts.

我所做的是使用 FileInstall 命令,该命令编译器将文件添加到可执行文件(并在运行时解压缩).

What I did was to use the FileInstall command which tells the compiler to add a file to the executable (and extract it when run).

遗憾的是,FileInstall命令不允许在源文件中使用变量,因此我不能简单地包含脚本本身(FileInstall, %A_ScriptFullPath%, %A_Temp%\%A_ScriptName%, 1).

Sadly, the FileInstall command will not allow the use of variables for the source file, so I cannot simply include the script itself (FileInstall, %A_ScriptFullPath%, %A_Temp%\%A_ScriptName%, 1).

作为一种变通方法,我最终将所有所需的热键提取到第二个文件,然后按照Elliot的建议进行解析,然后删除,并在脚本末尾添加#Include(必须 作为结尾,因为热键将终止自动执行部分).

As a work-around, I ended up extracting all of the desired hotkeys to a second file which I then parse as Elliot suggested, then delete, and #Include at the end of my script (it must be at the end since hotkeys will terminate the autoexecute section).

;;;;; Test.ahk ;;;;;

; Add hotkey file to executable and extract to Temp directory at runtime
FileInstall, Hotkeys.ahk, %A_Temp%\Hotkeys.ahk, 1

Loop
{
  ;Read a line from the extracted hotkey script and quit if error
  FileReadLine, line, %A_Temp%\Hotkeys.ahk, %A_Index%
    if ErrorLevel
      break

  ;Trim whitespace
  line=%line%

  ; Parse the line as in Elliot’s answer, but with tweaks as necessary
  ParseHotkey(line)
  …
}

FileDelete, %A_Temp%\Hotkeys.ahk ; Delete the extracted script
DisplayHotkeys()                 ; I ended up bulding and using a GUI instead
#Include, Hotkeys.ahk            ; It is included at compile-time, so no A_Temp



;;;;; Hotkeys.ahk ;;;;;

z::MsgBox foo
y::MsgBox bar

这篇关于显示自动热键热键列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆