;七级字符输入菜单 by Thinkai @2014-09-13
EscapeChar = | ;菜单分隔符。不建议用中文字符,可能会导致显示错误。默认为“,”
SetWorkingDir %A_ScriptDir%
;加载文件到数组
;q := file_menu_2_obj("q.txt")
;w := file_menu_2_obj("w.txt")

;无文件情况的演示
example =
(
男|高|娘
男|高|娘|搞基
男|高|娘|异性恋
男|高|娘|双性恋
男|高|猛
男|高|猪肝
男|富|帅|就|是|拽
男|帅
男|矮
男|矬
男|穷
女|白|富|美|就|是|拽
女|富
女|美
女|黑
女|穷
女|丑
人妖|人妖|人妖|人妖|人妖|人妖|人妖
畜生
禽类
微生物
)

if !FileExist(A_ScriptDir "\" A_ScriptName ".txt")
  FileAppend, %example%, % A_ScriptDir "\" A_ScriptName ".txt"

;演示段落完毕

e := file_menu_2_obj(A_ScriptDir "\" A_ScriptName ".txt")
Return

;写你的热键并调用函数
;::a::
;#q::
;调用函数
;create_menu(q)
;return

;::b::
;#w::
;create_menu(w)
;return

F1::
create_menu(e)
return


file_menu_2_obj(file){
;加载菜单文件到数组
if !file
  {
  MsgBox, 4112, 错误, 文件%file%不存在!
  return "Error:No file"
  }
Else
  {
  FileRead, content, %file%
  Return menu_string_2_obj(content)
  }
}

menu_string_2_obj(string){
;文本菜单项转为多维数组,请请定义好EscapeChar菜单分隔符
global EscapeChar
if (!EscapeChar)
  EscapeChar = ,
out := Object()
StringSplit, var, string, `n
Loop % var0
{
if (var%A_Index%)
StringSplit, tmp, var%A_Index%, %EscapeChar%
if (tmp%tmp0%)
  {
  if tmp0 = 1
    {
    if (!inobj(out,var%A_index%))
      out[var%A_index%] := "0"
    }
  Else if tmp0 = 2
    {
    if (!IsObject(out[tmp1]))
      {
      out[tmp1] := Object()
      }
    if (!inobj(out[tmp1],tmp2))
      out[tmp1][tmp2] := "0"
    }
  Else if tmp0 = 3
    {
    if (!IsObject(out[tmp1]))
      {
      out[tmp1] := Object()
      }
    if (!IsObject(out[tmp1][tmp2]))
      {
      out[tmp1][tmp2] := Object()
      }
    if (!inobj(out[tmp1][tmp2],tmp3))
      out[tmp1][tmp2][tmp3] := "0"
    }
  Else if tmp0 = 4
    {
    if (!IsObject(out[tmp1]))
      {
      out[tmp1] := Object()
      }
    if (!IsObject(out[tmp1][tmp2]))
      {
      out[tmp1][tmp2] := Object()
      }
    if (!IsObject(out[tmp1][tmp2][tmp3]))
      {
      out[tmp1][tmp2][tmp3] := Object()
      }
    if (!inobj(out[tmp1][tmp2][tmp3],tmp4))
      out[tmp1][tmp2][tmp3][tmp4] := "0"
    }
  Else if tmp0 = 5
    {
    if (!IsObject(out[tmp1]))
      {
      out[tmp1] := Object()
      }
    if (!IsObject(out[tmp1][tmp2]))
      {
      out[tmp1][tmp2] := Object()
      }
    if (!IsObject(out[tmp1][tmp2][tmp3]))
      {
      out[tmp1][tmp2][tmp3] := Object()
      }
    if (!IsObject(out[tmp1][tmp2][tmp3][tmp4]))
      {
      out[tmp1][tmp2][tmp3][tmp4] := Object()
      }
    if (!inobj(out[tmp1][tmp2][tmp3][tmp4],tmp5))
      out[tmp1][tmp2][tmp3][tmp4][tmp5] := "0"
    }
  Else if tmp0 = 6
    {
    if (!IsObject(out[tmp1]))
      {
      out[tmp1] := Object()
      }
    if (!IsObject(out[tmp1][tmp2]))
      {
      out[tmp1][tmp2] := Object()
      }
    if (!IsObject(out[tmp1][tmp2][tmp3]))
      {
      out[tmp1][tmp2][tmp3] := Object()
      }
    if (!IsObject(out[tmp1][tmp2][tmp3][tmp4]))
      {
      out[tmp1][tmp2][tmp3][tmp4] := Object()
      }
    if (!IsObject(out[tmp1][tmp2][tmp3][tmp4][tmp5]))
      {
      out[tmp1][tmp2][tmp3][tmp4][tmp5] := Object()
      }
    if (!inobj(out[tmp1][tmp2][tmp3][tmp4][tmp5],tmp6))
      out[tmp1][tmp2][tmp3][tmp4][tmp5][tmp6] := "0"
    }
  Else if tmp0 = 7
    {
    if (!IsObject(out[tmp1]))
      {
      out[tmp1] := Object()
      }
    if (!IsObject(out[tmp1][tmp2]))
      {
      out[tmp1][tmp2] := Object()
      }
    if (!IsObject(out[tmp1][tmp2][tmp3]))
      {
      out[tmp1][tmp2][tmp3] := Object()
      }
    if (!IsObject(out[tmp1][tmp2][tmp3][tmp4]))
      {
      out[tmp1][tmp2][tmp3][tmp4] := Object()
      }
    if (!IsObject(out[tmp1][tmp2][tmp3][tmp4][tmp5]))
      {
      out[tmp1][tmp2][tmp3][tmp4][tmp5] := Object()
      }
    if (!IsObject(out[tmp1][tmp2][tmp3][tmp4][tmp5][tmp6]))
      {
      out[tmp1][tmp2][tmp3][tmp4][tmp5][tmp6] := Object()
      }
    if (!inobj(out[tmp1][tmp2][tmp3][tmp4][tmp5][tmp6],tmp7))
      out[tmp1][tmp2][tmp3][tmp4][tmp5][tmp6][tmp7] := "0"
    }
  }
}
Return out
}
MsgBox % A_IsUnicode



create_menu(out){
;创建并显示菜单函数,传入菜单数组,菜单点击到MenuHandler标签
keys := ["",1,2,3,4,5,6,7,8,9,0,"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
Menu, main, add,
Menu, main,DeleteAll
index1 = 1
for k,v in out
{
index1 += 1
if (IsObject(v))
  {
  Menu, main_%k%, add,
  Menu, main_%k%, DeleteAll
  Menu, main, add, % k ? "(&" keys[index1] ") " k : "", :main_%k%
  subkey1 := k
  index2 = 1
  for k,v in out[subkey1]
  {
  index2 += 1
  if (IsObject(v))
    {
    Menu, main_%subkey1%_%k%, add,
    Menu, main_%subkey1%_%k%, DeleteAll
    Menu, main_%subkey1%, add, % k ? "(&" keys[index2] ") " k : "", :main_%subkey1%_%k%
    subkey2 := k
    index3 = 1
    for k,v in out[subkey1][subkey2]
    {
    index3 += 1
    if (IsObject(v))
      {
      Menu, main_%subkey1%_%subkey2%_%k%, add,
      Menu, main_%subkey1%_%subkey2%_%k%, DeleteAll
      Menu, main_%subkey1%_%subkey2%, add, % k ? "(&" keys[index3] ") " k : "", :main_%subkey1%_%subkey2%_%k%
      subkey3 := k
      index4 = 1
      for k,v in out[subkey1][subkey2][subkey3]
      {
      index4 += 1
      if (IsObject(v))
        {
        Menu, main_%subkey1%_%subkey2%_%subkey3%_%k%, add,
        Menu, main_%subkey1%_%subkey2%_%subkey3%_%k%, DeleteAll
        Menu, main_%subkey1%_%subkey2%_%subkey3%, add, % k ? "(&" keys[index4] ") " k : "", :main_%subkey1%_%subkey2%_%subkey3%_%k%
        subkey4 := k
        index5 = 1
        for k,v in out[subkey1][subkey2][subkey3][subkey4]
        {
        index5 += 1
        if (IsObject(v))
          {
          Menu, main_%subkey1%_%subkey2%_%subkey3%_%subkey4%_%k%, add,
          Menu, main_%subkey1%_%subkey2%_%subkey3%_%subkey4%_%k%, DeleteAll
          Menu, main_%subkey1%_%subkey2%_%subkey3%_%subkey4%, add, % k ? "(&" keys[index5] ") " k : "", :main_%subkey1%_%subkey2%_%subkey3%_%subkey4%_%k%
          subkey5 := k
          index6 = 1
          for k,v in out[subkey1][subkey2][subkey3][subkey4][subkey5]
          {
          index6 += 1
          if (IsObject(v))
            {
            Menu, main_%subkey1%_%subkey2%_%subkey3%_%subkey4%_%subkey5%_%k%, add,
            Menu, main_%subkey1%_%subkey2%_%subkey3%_%subkey4%_%subkey5%_%k%, DeleteAll
            Menu, main_%subkey1%_%subkey2%_%subkey3%_%subkey4%_%subkey5%, add, % k ? "(&" keys[index6] ") " k : "", :main_%subkey1%_%subkey2%_%subkey3%_%subkey4%_%subkey5%_%k%
            subkey6 := k
            index7 = 1
            for k,v in out[subkey1][subkey2][subkey3][subkey4][subkey5][subkey6]
            {
            index7 += 1
            Menu, main_%subkey1%_%subkey2%_%subkey3%_%subkey4%_%subkey5%_%subkey6%, add, % k ? "(&" keys[index7] ") " k : "", MenuHandler
            }
            }
          Else
            {
            Menu, main_%subkey1%_%subkey2%_%subkey3%_%subkey4%_%subkey5%, add, % k ? "(&" keys[index6] ") " k : "", MenuHandler
            }
          }
          }
        Else
          {
          Menu, main_%subkey1%_%subkey2%_%subkey3%_%subkey4%, add, % k ? "(&" keys[index5] ") " k : "", MenuHandler
          }
        }
        }
      Else
        {
        Menu, main_%subkey1%_%subkey2%_%subkey3%, add, % k ? "(&" keys[index4] ") " k : "", MenuHandler
        }
      }
      }
    Else
      {
      Menu, main_%subkey1%_%subkey2%, add, % k ? "(&" keys[index3] ") " k : "", MenuHandler
      }
    }
    }
  Else
    {
    Menu,  main_%subkey1%, add, % k ? "(&" keys[index2] ") " k : "", MenuHandler
    }
  }
  }
Else
  {
  Menu, main, add, % k ? "(&" keys[index1] ") " k : "", MenuHandler
  }
}
menu, main, show
}

inobj(obj,key){
;判断数组内是否有指定字符的键值或变量
var = 0
for k,v in obj
{
if if (k=key and v=key)
  var = 3
Else if (k=key)
  var := var>1 ? var : 1
Else if (v=key)
  var := var>2 ? var : 2
}
Return var
}


MenuHandler:
;转存剪切板  直接粘贴 支持中文
clip := ClipboardAll
;发送括号后面的内容
Clipboard := RegExReplace(A_ThisMenuItem,"\(.*\)\s*(.*)","$1")
Send, ^v
Sleep,200
Clipboard := clip
return

 

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