JURIA @Wiki
myShortInput.ahk
最終更新:
juria
-
view
myShortInput.ahk
/*
myShortInput.ahk 2007-12-02 版
カーソル位置指定と定型文位置指定挿入
・クリップボードに url だけの場合は、はてなダイアリー・@Wiki の
リンクの書式。カーソル位置ははてなの場合だけエイリアス入力位置。
クリップボード内の url の整形は Refo を使用。
(http://www.beyond-boundaries.info/)
・それ以外は定型文リストから選択後、貼り付け位置指定メニュー。
リストは migemo によるローマ字インクリメンタルサーチ。
migemo.ahk を使用(http://lukewarm.s101.xrea.com/myscripts/index.html)
必要なファイルは migemo.ahk を参照のこと。
・リスト上では、Tab でコントロールを移動、↑↓キーでリスト移動、
Enter で決定、ESC でキャンセル。マウス操作もオッケー。
・貼り付け位置はニーズに応じてメニューに登録
・定型文リスト書式:短縮語 | 定型文
・Windows 標準のショートカットキーをサポートするエディットでしか
正しく動作しない。
ToDo:定型文とクリップボード文字列の同時挿入(できないかも^^;)
:エディタによって送信キーを使い分ける。
Shift + Insert(コピー)
Ctrl + Delete(切り取り)
Ctrl + Insert(貼り付け)
*/
#Persistent
#SingleInstance
#Include %A_ScriptDir%\migemo.ahk
; 短縮語・定型文のリストファイルを指定
abbrev = E:\etc\static-abbrev.ini
; refo.exe のパスを指定
refo = D:\Application\Text_Editor\util\Refo\refo.exe
V = ^v
C = ^C
X = ^x
L = {HOME}
R = {End}
L1 = {Left}
R1 = {Right}
; マウスの下のコントロールの ClassNN を取得して変数に格納
MouseGetPos,,,,ctrl,2
; url の取り出し
path = http
StringGetPos, pos, Clipboard, %path%,
; クリップボードの文字列が url で始まる場合のみ
if pos = 0
{
Menu, link, Add, はてな(&D), hatena
Menu, link, Add, @Wiki(&W), wiki
Menu, link, Add, (&U)そのまま, url
Menu, link, Show
Menu, link, Delete
Return
hatena:
active()
Runwait, %refo% /RE "s/^/[/g" "s/$/:title=]/g"
Send, %V%%L1%
ExitApp
wiki:
RunWait, %refo% /RE "s/^/[[>/g" "s/$/]]/g"
;RunWait, %refo% /RE "s/$/]]/g" "s/^/[[>/g"
active()
Send, %V%
ExitApp
url:
active()
Send, %V%
ExitApp
}
else ; url 以外は定型文選択
{
GUI, Margin, 1, 1
Gui, add, Edit, vEdit gMatch w200
Gui, Add, ListView, r15 w200 -Multi Grid vAbbrevList gAbbrevList, 短縮語|定型文
Gui, -Caption +Resize
; デフォルトボタン非表示で Enter に動作割り当て
Gui, Add, Button, xm+10 Hidden Default gButtonCopy, Copy
; Gui, Add, Button, x+20 Hidden gButtonCancel, Cancel
MigemoOpen(A_ScriptDir "\dict\migemo-dict")
Loop, read, %abbrev%
{
lists()
}
Gui, Show, , Shortinput
Return
}
; Edit, ListView リサイズ
GuiSize:
width:=A_GuiWidth-1
height:=A_GuiHeight-22
GuiControl, Move, AbbrevList, w%width% h%height%
GuiControl, Move, Edit, w%width%
Return
Match:
GuiControlGet,Ed,,Edit
len := StrLen(Ed)
LV_Delete()
GUIControl, -Redraw, AbbrevList
MigemoSet(Ed)
Loop,read, %abbrev%
{
name := A_LoopReadLine
Loop, Parse, name, "`n"
{
StringSplit, compi, name, |
if(len > 0)
{
ifInString, A_LoopField, %Ed%
{
LV_Add(" ", compi1, compi2)
}
else if(MigemoMatch(compi1) && len > 1)
{
LV_Add(" ", compi1, compi2)
}
}
if(len = 0)
lists()
}
}
LV_Modify(1,"Select Focus")
GUIControl, +Redraw, AbbrevList
Return
AbbrevList:
if A_GuiEvent = DoubleClick
selection()
if A_GuiEvent = ColClick ; 列見出しだったら何もしない
Return
ButtonCopy:
selection()
menu:
Menu, pattern, Add, a:カーソル位置に挿入, past
Menu, pattern, Add, b:挿入後1文字左に, past_left
Menu, pattern, Add, c:挿入後1文字右に, past_right
Menu, pattern, Add, d:行頭に挿入, past_top ; カーソールは行末
Menu, pattern, Add, e:行末に挿入して改行, past_end
Menu, pattern, Add, f:前行末に挿入, past_prev ;
Menu, pattern, Add, g:改行して挿入, past_next
Menu, pattern, Show
Menu, pattern, Delete
past:
active()
Send, %V%
ExitApp
past_left:
active()
Send, %V%%L1%
ExitApp
past_right:
active()
Send, %V%%R1%
ExitApp
past_top:
active()
Send, %X%%L%%V%%R%
ExitApp
past_end:
active()
Send, %R%%V%`n
ExitApp
past_prev:
active()
Send, %X%%L%%L1%%V%%R%
ExitApp
past_next:
active()
Send, %R%`n%V%
ExitApp
; ------ 関数 -----
lists()
{
global
StringSplit, compi, A_LoopReadLine, |
LV_Add(" ", compi1, compi2)
LV_ModifyCol(1, "Sort Auto") ; 1列目でソート、列幅調節して表示
LV_Modify(1,"Select Focus") ; 1行目を選択状態・フォーカス
}
selection()
{
global
; 選択されている(フォーカスがある)項目番号を取得
Selected := LV_GetNext(0, "F")
; LV_GetText(OutputVar, RowNumber [, ColumnNumber])
LV_GetText(Name, Selected, 1)
LV_GetText(ID, Selected, 2)
Clipboard = %ID%
Gosub, menu
Return
}
active()
{
global
WinActivate, ahk_id %ctrl%
sleep, 500
}
GuiEscape:
GuiClose:
ButtonCancel:
MigemoClose()
ExitApp
-