按任意键时都能触发同一个标签或者函数

#NoEnv
SetBatchLines -1
SetWorkingDir %A_ScriptDir%

s:="||Home|End|Ins|Del|PgUp|PgDn|Left|Right|Up|Down|NumpadEnter|"
Loop 254
  k:=GetKeyName(Format("VK{:X}",A_Index)), s.=InStr(s,"|" k "|") ? "" : k "|"
For k,v in { Escape:"Esc", Control:"Ctrl", Backspace:"BS" }
  s:=StrReplace(s, k, v)
s:=Trim(RegExReplace(s,"\|+","|"), "|")
/*
Loop, Parse, s, |
{  ; 只能够禁用大多数热键和组合
  Hotkey %A_LoopField%, Off, UseErrorLevel
  Hotkey ~%A_LoopField%, Off, UseErrorLevel
  Hotkey ^%A_LoopField%, Off, UseErrorLevel
  Hotkey #%A_LoopField%, Off, UseErrorLevel
  Hotkey !%A_LoopField%, Off, UseErrorLevel
  Hotkey +%A_LoopField%, Off, UseErrorLevel
  Hotkey ^!%A_LoopField%, Off, UseErrorLevel
  Hotkey ^+%A_LoopField%, Off, UseErrorLevel
  Hotkey ^#%A_LoopField%, Off, UseErrorLevel
}
*/
MsgBox % s
; For _,v in StrSplit(CopyOfData, "|")
;   Hotkey %v%, On

; ============================================

arr:=[]
Loop 512 {
  arr[getkeyname(format("vk{:x}",a_index))]:=1
  arr[getkeyname(format("sc{:x}",a_index))]:=1
}


hotkey, IfWinActive, ahk_class AHKEditor
For k,v in arr
  if (k!="")&&(k!="LButton")&&(k!="RButton")
    hotkey, ~*%k%, 记录, On UseErrorLevel
hotkey, if
Return

记录:
MsgBox 按键触发
Return

 

声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。