プラグインのイベント以外に、キーボードのイベントが利用できます。 Delphi の OnKeyDown と同じ処理が使用できます。 最初は検索ダイアログが表示している場合の判定はできないと思ってメッセージダイアログを表示して対応していましたが、トップウィンドウのタイトル文字の判定で対応が可能でした。
function TReadOnlyFrame.PluginProc(hwnd: HWND; nMsg: Cardinal; wParam: WPARAM; lParam: LPARAM): LRESULT;
var
bResult: Boolean;
begin
Result := 0;
case nMsg of
MP_QUERY_PROPERTIES:
begin
Result := LRESULT(QueryProperties);
end;
MP_SET_PROPERTIES:
begin
Result := LRESULT(SetProperties);
end;
MP_PRE_TRANSLATE_MSG:
Result := LRESULT(PreTranslateMessage(hwnd, PMsg(lParam)^));
end;
end;
function TReadOnlyFrame.PreTranslateMessage(hwnd: HWND; var Msg: tagMSG): Boolean;
var
LCtrl, LShift: Boolean;
iPos1: Integer;
wHwnd1: Thandle;
sCaption: String;
iLen1: Integer;
sStr1: String;
sStr6: String;
sStr12: String;
StrList13: TStringList;
begin
//書込禁止
//// 3.3.2
if Editor_Info(hwnd, MI_GET_READ_ONLY, 0) = 0 then
begin
Result := FALSE;
Exit;
end;
if Msg.message = WM_KEYDOWN then
begin
//トップウィンドウのタイトル
wHwnd1 := GetForegroundWindow;
SetLength(sCaption, 1023);
iLen1 := GetWindowText(wHwnd1, PChar(sCaption), Length(sCaption) - 1);
SetLength(sCaption, iLen1);
sStr1 :=sCaption;
iPos1 := Pos(UpperCase(TITLE_BAR_MERY), UpperCase(sStr1));
//キー状態
LCtrl := GetKeyState(VK_CONTROL) < 0;
LShift := GetKeyState(VK_SHIFT) < 0;
//プラグインの起動
bRun := FALSE;
bRun1 := FALSE;
bRun2 := FALSE;
bRun3 := FALSE;
bRun4 := FALSE;
bRun5 := FALSE;
if CheckPlugin('OutLine.dll') = TRUE then
begin
bRun1 := TRUE;
end;
//
if CheckPlugin('MeryOutLine.dll') = TRUE then
begin
bRun2 := TRUE;
end;
//
if CheckPlugin('MeryColCount.dll') = TRUE then
begin
bRun3 := TRUE;
end;
//
if CheckPlugin('MarkdownPreview.dll') = TRUE then
begin
bRun4 := TRUE;
end;
//
if CheckPlugin('WebPreview.dll') = TRUE then
begin
bRun5 := TRUE;
end;
//
if (bRun1 = TRUE) or (bRun2 = TRUE) or (bRun3 = TRUE) or (bRun4 = TRUE) or (bRun5 = TRUE)then
begin
bRun := TRUE;
end;
//キーボード
if Msg.wParam = VK_RETURN then
begin
//Ctrl なら無条件
if (LShift = FALSE) and (LCtrl = TRUE) then
begin
//終了確認
ConfirmExit(hwnd);
//結果
sStr12 := ExtractFilePath(ParamStr(0)) + MACROS_FOLDER_NAME + '\' + MACROS_FILE_NAME_RESULT;
if System.SysUtils.FileExists(sStr12, FALSE) = TRUE then
begin
//読込
StrList13 := TStringList.Create;
try
StrList13.LoadFromFile(sStr12);
sStr6 := StrList13.Strings[0];
finally
StrList13.Free;
end;
end;
//全て書込禁止
if (BoolExitCtrlEnter = TRUE) and (sStr6 = MACROS_FILE_NAME_RESULT_TRUE) then
begin
Editor_ExecCommand(hwnd, MEID_FILE_CLOSE_ALL);
Result := TRUE;
Exit;
end
else
begin
Result := FALSE;
Exit;
end;
end
//Enter で -Mery が前面
else if (LShift = FALSE) and (LCtrl = FALSE) and (iPos1 > 0) then
begin
//終了確認
ConfirmExit(hwnd);
//結果
sStr12 := ExtractFilePath(ParamStr(0)) + MACROS_FOLDER_NAME + '\' + MACROS_FILE_NAME_RESULT;
if System.SysUtils.FileExists(sStr12, FALSE) = TRUE then
begin
//読込
StrList13 := TStringList.Create;
try
StrList13.LoadFromFile(sStr12);
sStr6 := StrList13.Strings[0];
finally
StrList13.Free;
end;
end;
//全て書込禁止でプラグインが起動されていない
if (BoolExitEnter = TRUE) and (sStr6 = MACROS_FILE_NAME_RESULT_TRUE) and (bRun = FALSE) then
begin
Editor_ExecCommand(hwnd, MEID_FILE_CLOSE_ALL);
Result := TRUE;
Exit;
end
else
begin
Result := FALSE;
Exit;
end;
end
//
else
begin
Result := FALSE;
Exit;
end;
end
//
else if Msg.wParam = VK_ESCAPE then
begin
//Escape で -Mery が前面
if (iPos1 > 0) then
begin
//終了確認
ConfirmExit(hwnd);
//結果
sStr12 := ExtractFilePath(ParamStr(0)) + MACROS_FOLDER_NAME + '\' + MACROS_FILE_NAME_RESULT;
if System.SysUtils.FileExists(sStr12, FALSE) = TRUE then
begin
//読込
StrList13 := TStringList.Create;
try
StrList13.LoadFromFile(sStr12);
sStr6 := StrList13.Strings[0];
finally
StrList13.Free;
end;
end;
//全て書込禁止でプラグインが起動されていない
if (BoolExitEscape = TRUE) and (sStr6 = MACROS_FILE_NAME_RESULT_TRUE) and (bRun = FALSE) then
begin
Editor_ExecCommand(hwnd, MEID_FILE_CLOSE_ALL);
Result := TRUE;
Exit;
end
else
begin
Result := FALSE;
Exit;
end;
end
else
begin
Result := FALSE;
Exit;
end;
end
else
begin
Result := FALSE;
Exit;
end;
end;
//
Result := FALSE;
end;