[办公]input-ahk(Flapy-Autohotkey):用ahk写一个简单输入法

改名是准备以后加一个切换其他输入法的选项,方便不会小鹤输入法的人使用,独乐乐不如众乐乐

脚本说明:

  1. 用ahk 写的一个简单输入法,自带的码表是小鹤音形
  2. 适合使用形码,无数字键候选功能
  3. shift 切换中英文
  4. ; 上屏第二码
  5. space 上屏文字,无候选词则上屏编码
  6. enter 上屏编码
  7. 输入状态下 shift 切换中英文并上屏编码
  8. 输入状态下 esc 清空编码并切换为英文
  9. 使用 unicode 编码, 这样在 qq 输入框输出的字符好像会好看一点,支持更多符号
  10. 部分过程封装为函数,看起来应该显得更简洁, 可能吧…
  11. 加了个托盘图标,三十秒钟画出来,丑是肯定的
  12. 文章末尾有下载连接

 

;>> 小鹤拼音输入法ahk版本
;>> input 0.2
;>> AHKVerion: Unicode 64bit
;>> Author: fuwt
;>> date: 2017-05-2
;>> 分号选择第二码
;>> shift切换中英文
sendmode input
SetWorkingDir %A_ScriptDir%
#SingleInstance, force
FileEncoding UTF-8
CoordMode, Caret, Screen
CoordMode, Mouse, Screen
global dic := {}
global KeyText
global StrText
global key
global symbolcount := {}
GroupAdd, EN, ahk_class
GroupAdd, EN, ahk_class Vim
GroupAdd, EN, ahk_class TTOTAL_CMD
GroupAdd, EN, ahk_class ConsoleWindowClass
GroupAdd, EN, ahk_class Photoshop
GroupAdd, EN, ahk_class AfxMDIFrame140u

; global box := 0   ;box等于0不显示候选框
ReadDic("dic_flapy")
ReadDic("dic_user")

Gui, Margin, 10, 3
Gui, font, s13
Gui, +ToolWindow -Caption +AlwaysOnTop +LastFound -DPIScale
Gui, color, ffffff
Gui, Add, text, cblue r0.8 vKeyText,test font
; Gui, Add, text, w300 h1 +0x4, split
Gui, font, s16 w700
Gui, Add, text, r1.2 vStrText, test font
UpdateIcon()

loop, 26
{
	thisHotkey := Chr(A_Index + 96)
	Hotkey, ~%thisHotkey%, flapy
}
Loop
{
    WinWaitActive, ahk_group EN
    switch(0)
    ActiveHwnd := WinExist("A")
    WinWaitNotActive, ahk_id %ActiveHwnd%
}
return
flapy:
    key .= StrReplace(A_ThisHotkey, "~")
	; key .= A_ThisHotkey
	ShowBox()
	if (dic[key] && InStr(dic[key],"|") < 1 && StrLen(key) = 4)
        SendStr()
	else if (StrLen(key) = 5 && dic[SubStr(key,1,4)])
    {
		str := StrSplit(dic[SubStr(key,1,4)], "|")
        send {bs 5}
        Send % str[1] StrReplace(A_ThisHotkey,"~")
        key := ""
        goto flapy
	}
return

shift::
	Suspend Toggle
    UpdateIcon()
	key := ""
	Gui Hide
return
; 本人使用CapsLock热键, 后面两个命令避免弹出候选框
~CapsLock::
    Suspend on
return
CapsLock Up::
    Suspend off
return
~!s::
~rbutton::
    Suspend on
    sleep 350
    Suspend off
return

; 标点自动上屏文字
,::SendSymbol(",")
?::SendSymbol("?")
!::SendSymbol("!")
`;::SendSymbol(";")
-::SendSymbol("—")
^::SendSymbol("……")
~::SendSymbol("~")
(::SendSymbol("(")
)::SendSymbol(")")
[::SendSymbol("〔")
]::SendSymbol("〕")
<::SendSymbol("《") >::SendSymbol("》")
'::DoubleSymbol("‘","’")
"::DoubleSymbol("“","”")
; 特殊处理几个符号
#UseHook on   ; 冒号不知道怎么加$,直接UseHook,避免热键触发本身
/::
    if (!StrLen(dic[key]) && StrLen(Key))
    {
        key .= "/"
        ShowBox()
        send /
    }
    else
        SendSymbol("、")
return
:::
    if (!StrLen(dic[key]) && StrLen(Key) || key="http" || key="https" || key="file" || key="ftp")
    {
        key .= ":"
        ShowBox()
        send :
    }
    else
        SendSymbol(":")
return
.::
    if (!StrLen(dic[key]) && StrLen(Key) || key="www" || key="baidu" || key="google" || key="chn")
    {
        key .= "."
        ShowBox()
        send .
    }
    else
        SendSymbol("。")
return
#UseHook off
#If StrLen(key)
space::
    SendStr()
return
`;::
    SendStr(2)
return
~@::
~0::
~1::
~2::
~3::
~4::
~5::
~6::
~7::
~8::
~9::
	key .= StrReplace(A_ThisHotkey,"~")
	ShowBox()
return
esc::
    CleanCode()
    Suspend on
    UpdateIcon()
return
~Backspace::
	key := SubStr(key, 1, StrLen(key) - 1)
	ShowBox()
	if (StrLen(key)=0)
		Gui Hide
return
enter::
    SendCode()
return
shift::
    SendCode()
    Suspend on
    UpdateIcon()
return
#If StrLen(key)=0
; [::send 「」『』[]〔〕【】
; <::send 《》〈〉

#if WinActive("ahk_group EN")
~esc:: switch(0)
#if


ShowBox(){
	if (box = 0)
		return
	GuiControl text, KeyText, % key
	GuiControl Move, KeyText, % "w" StrLen(key)*13
	GuiControl text, StrText, % dic[key]
    posx := posY := 0
    if(A_CaretX){
        posX := A_CaretX + 10
        posY := A_CaretY + 20
    }
	Gui show, AutoSize NA x%posX% y%posY%
}

ReadDic(dictionary){
	Loop, Read, % dictionary
    {
        line := StrSplit(A_LoopReadLine,A_Tab)
        if (StrLen(dic[line[2]]))
            dic[line[2]] .= "|" . line[1]
        else
            dic[line[2]] := line[1]
    }
}
SendCode(){
	key := ""
	Gui Hide
}
CleanCode(){
    DllCall("SendMessage", UInt, WinActive("A"), UInt, 80, UInt, 1, UInt, DllCall("LoadKeyboardLayout", Str,, UInt, 1))
    i := StrLen(key)
    send {bs %i%}
	key := ""
	Gui Hide
}
SendStr(n:=1){
    if (StrLen(dic[key]))
    {
        if (InStr(dic[key], "|"))
        {
            str := StrSplit(dic[key], "|")
            i := StrLen(key)
            send {bs %i%}
            clipsave := clipboardall
            clipboard := str[n]
            Send % clipboard
            clipboard := clipsave
            clipsave := ""
        }
        else{
            i := StrLen(key)
            send {bs %i%}
            clipsave := clipboardall
            clipboard := dic[key]
            send % clipboard
            clipboard := clipsave
            clipsave := ""
        }
    }
    else
        SendCode()
	key := ""
	Gui Hide
}
SendSymbol(symbol := ""){
    SendStr()
    send % symbol
}
DoubleSymbol(a := "", b := ""){
    SendStr()
    if (!symbolcount[A_ThisHotkey])
        symbolcount[A_ThisHotkey] := 0
    symbolcount[A_ThisHotkey] += 1
    if (mod(symbolcount[A_ThisHotkey],2) = 0)
        ; send {Right}
        send % b
    else
        ; send % a b "{left}"
        send % a
}
UpdateIcon(){
    if (A_IsSuspended = 1)
        menu tray, icon, ico\eng.ico,,1
    else
        menu tray, icon, ico\chi.ico,,1
}
switch(i := "A"){
    if (i = 1)
        Suspend off
    else if (i = 0)
        Suspend on
    else
        Suspend Toggle
    UpdateIcon()
	key := ""
	Gui Hide
}
下载权限
查看
  • 免费下载
    评论并刷新后下载
    登录后下载
  • {{attr.name}}:
您当前的等级为
登录后免费下载登录 小黑屋反思中,不准下载! 评论后刷新页面下载评论 支付以后下载 请先登录 您今天的下载次数(次)用完了,请明天再来 支付积分以后下载立即支付 支付以后下载立即支付 您当前的用户组不允许下载升级会员
您已获得下载权限 您可以每天下载资源次,今日剩余

给TA捐赠
共{{data.count}}人
人已捐赠
其他案例

[办公]Autohotkey在office中的应用

2017-2-19 18:10:44

其他案例

[办公]资源管理器中文首字母快搜

2017-2-20 21:36:52

14 条回复 A文章作者 M管理员
  1. tpg

    感觉这个程序放在U盘里比较好,这样到哪里都可以用自己习惯的输入法了。另外挂载多个词库的功能非常棒。

    • AHK中文社区

      你这个想法真是不错!

    • 支持站长!!

    • 感觉你这个想法不错!

  2. tpg

    作者很有创意,我已经处理好了五笔的码表,配合这个脚本来作为默认的输入法使用了。以下根据个人习惯对原来的代码作了一点点简单的修改。

    ;添加单引号作为第三候选词上屏的按键
    '::
    if InStr(dic[key], "|")
    str := StrSplit(dic[key], "|")
    Send, % str[3]
    key := ""
    Gui, Hide
    return

    ;中文标点添加了几个符号
    #If StrLen(key)=0
    .::Send, 。
    ?::Send, ?
    !::Send, !
    ,::Send, ,
    /::Send, 、
    \::Send, 、
    :::Send, :
    `;::Send, ;
    _::Send, ——
    ^::Send, ……
    ::Send, 》

    ;候选窗格式部分添加如下一行,用来解决第二、第三以及更多的候选词显示不全的问题
    GuiControl, Move, StrText, % "w" StrLen(key)*100

  3. 火冷

    头痛的是我好像只有H2和L1的,竟然还一个V2,有点混乱啊 ➡

  4. 琪c

    想找这种完整的, 可是原址下不到了, 哪里能下到?

    • chn.fwt

      链接:https://pan.baidu.com/s/1t0TsW2oR1H1eO6vWDRQGOg
      提取码:jt2o

      coding仿佛是不能用了,文章也不能修改,我重新在百度网盘传了一份完整版。

  5. 东亚强夫

    这 代码 没有 用 呀

  6. chn.fwt

    链接:https://pan.baidu.com/s/1t0TsW2oR1H1eO6vWDRQGOg
    提取码:jt2o

    coding仿佛是不能用了,文章也不能修改,我重新在百度网盘传了一份完整版。

  7. lixin_

    链接失效了

  8. AlbertWang

    链接失效了,建议放github或gitee更好

  9. ahkjoo

    可以,可以终于看懂了

个人中心
购物车
优惠劵
有新私信 私信列表
搜索