Skip to content

Commit

Permalink
keymapTray v1.1.0
Browse files Browse the repository at this point in the history
* [+] 增加“获取当前窗口信息”功能(热键触发)
* [+] 增加“编辑配置文件”、“重新读入配置文件”功能菜单
* [+] 增加“热键信息”功能菜单
  • Loading branch information
cataerogong committed Feb 26, 2024
1 parent 35aae68 commit f22ade7
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 25 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 CataeroGong
Copyright (c) 2023-2024 CataeroGong

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 6 additions & 2 deletions exe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@

```ini
[Default]
debug = False
; 两种【键谱】热键模式:
; 注:使用 AHK 热键格式,=空 表示不设置该热键
; 1. 组合键(常用 AHK 修饰键:^:Ctrl, !:Alt, +:Shift, #:Win)
; 注: 使用 AHK 热键格式,=空 表示不设置该热键
; 常用 AHK 修饰键: ^:Ctrl, !:Alt, +:Shift, #:Win
; 1. 组合键
hotkey1=^!k
; 2. 单键双击
hotkey2=Esc
; 获取当前窗口信息热键
hotkey_GetWinInfo=^!i
[Keymaps]
; “键谱”与应用窗口对应关系
; 应用窗口标题关键字 = “谱匣”参数
Expand Down
22 changes: 18 additions & 4 deletions exe/build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,28 @@ set compiler=D:\Programs\AutoHotkey2\Compiler\Ahk2Exe.exe
set base=D:\Programs\AutoHotkey2\AutoHotkey64.exe

if exist keymap.ico set "icon=/icon keymap.ico"

if "%~1" neq "" goto :%~1

call :clean
call :exe
call :tray

exit /b

:clean
if exist dist rmdir /s /q dist
mkdir dist
mkdir dist\keymap
mkdir dist\keymap\data
exit /b

:exe
if not exist dist\keymap\data mkdir dist\keymap\data
"%base%" encode.ahk2 keymap.py keymap.pye
"%compiler%" /base "%base%" /in keymap.ahk2 /out dist\keymap\keymap.exe %icon%
xcopy /s _runtime dist\keymap\_runtime\
xcopy /y /s _runtime dist\keymap\_runtime\
exit /b

:tray
if not exist dist\keymap\data mkdir dist\keymap\data
"%compiler%" /base "%base%" /in keymapTray.ahk2 /out dist\keymap\keymapTray.exe %icon%
copy /y keymapTray.ini dist\keymap\
exit /b
4 changes: 4 additions & 0 deletions exe/keymap.ahk2
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#Include keymap.pye
;@Ahk2Exe-IgnoreEnd
;@Ahk2Exe-AddResource keymap.pye, #2
;@Ahk2Exe-SetName keymap
;@Ahk2Exe-SetDescription 谱匣 - “键谱”网页的辅助增强程序
;@Ahk2Exe-SetCopyright Copyright (c) CataeroGong
;@Ahk2Exe-SetVersion 3.3.0

FileEncoding("UTF-8-RAW")
DetectHiddenWindows True
Expand Down
112 changes: 101 additions & 11 deletions exe/keymapTray.ahk2
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#Requires AutoHotkey v2.0
#SingleInstance Force
;@Ahk2Exe-SetName keymapTray
;@Ahk2Exe-SetDescription keymapTray - “谱匣”的辅助增强程序
;@Ahk2Exe-SetCopyright Copyright (c) CataeroGong
;@Ahk2Exe-SetVersion 1.1.0

FileEncoding("UTF-8-RAW")
DetectHiddenWindows True
Expand All @@ -10,6 +14,7 @@ KEYMAP_TITLE := "键谱 【精装礼盒版 *^____^* 】"
SplitPath(A_ScriptFullPath, , &_DIR, &_EXT, &_NAME, &_DRIVE)

IniFile := A_ScriptDir . "\" . _NAME . ".ini"
LogFile := A_ScriptDir . "\" . _NAME . ".log"

ExeFile := A_ScriptDir . "\keymap.exe"
If (FileExist(ExeFile))
Expand All @@ -19,8 +24,14 @@ Else {
ExitApp
}

debug := StrLower(IniRead(IniFile, "Default", "debug", ""))
If debug == "true" || debug == "1"
debug := True
Else
debug := False
hotkey1 := IniRead(IniFile, "Default", "hotkey1", "")
hotkey2 := IniRead(IniFile, "Default", "hotkey2", "")
hotkeyGWI := IniRead(IniFile, "Default", "hotkey_GetWinInfo", "")
kms := IniRead(IniFile, "Keymaps")
keymaps := Array()
Loop Parse, kms, "`n", A_Space A_Tab
Expand All @@ -44,14 +55,19 @@ ToggleKeyMap2(params*)
}
}
ShowKeymap(params*) {
Global keymaps
Global
T := ""
P := ""
For km In keymaps {
If km[1] && WinActive(km[1]) {
T := km[1]
P := " " . km[2]
Break
}
}
If (debug) {
FileAppend("窗口标题=" . WinGetTitle("A") . ", 关键字=" . T . ", 谱匣参数=" . P . "`n", LogFile)
}
Run(ExeFile . P)
}
HideKeymap(params*) {
Expand All @@ -64,25 +80,99 @@ ExitKeymap(ExitReason, ExitCode) {
WinClose(KEYMAP_TITLE)
}
}
ShowActiveWindowInfo(params*) {
hwnd := WinExist("A")
If (!hwnd)
Return
id := "ahk_id " . hwnd
title := WinGetTitle(id)
exe := WinGetProcessName(id)
path := WinGetProcessPath(id)
cls := WinGetClass(id)
pid := WinGetPID(id)
MsgBox("【窗口标题】`n" . title . "`n`n"
. "【执行文件】`nahk_exe " . exe "`nahk_exe " . path . "`n`n"
. "【窗口类】`nahk_class " . cls . "`n`n"
. "【进程ID】`nahk_pid " . pid . "`n`n"
. "【窗口句柄】`nahk_id " . hwnd . "`n`n"
. "* Ctrl+C 复制信息`n`n"
, "当前窗口信息")
}
ShowHotkeys(params*) {
MsgBox("显示/隐藏【键谱】(组合键): " . hotkey1 . "`n`n"
. "显示/隐藏【键谱】(双击键): " . hotkey2 . "`n`n"
. "获取当前窗口信息:" . hotkeyGWI . "`n`n"
. "-------------------------`n"
. "常用 AHK 修饰键:`n^:Ctrl, !:Alt, +:Shift, #:Win"
, "keymapTray 热键")
}
EditConfig(params*) {
Run(IniFile)
}
ReloadConfig(params*) {
Global
debug := StrLower(IniRead(IniFile, "Default", "debug", ""))
If debug == "true" || debug == "1"
debug := True
Else
debug := False
hotkey1_new := IniRead(IniFile, "Default", "hotkey1", "")
hotkey2_new := IniRead(IniFile, "Default", "hotkey2", "")
hotkeyGWI_new := IniRead(IniFile, "Default", "hotkey_GetWinInfo", "")
kms := IniRead(IniFile, "Keymaps")
keymaps := Array()
Loop Parse, kms, "`n", A_Space A_Tab
{
a := StrSplit(A_LoopField, "=", A_Space A_Tab, 2)
If (a.Length == 2) {
keymaps.Push(a)
}
}
if (hotkey1 != hotkey1_new) {
Try
If (hotkey1)
Hotkey(hotkey1, "Off")
hotkey1 := hotkey1_new
if (hotkey1)
Hotkey(hotkey1, ToggleKeyMap, "On")
}
if (hotkey2 != hotkey2_new) {
Try
If (hotkey2)
Hotkey("~" . hotkey2 . " UP", "Off")
hotkey2 := hotkey2_new
if (hotkey2)
Hotkey("~" . hotkey2 . " UP", ToggleKeyMap2, "On")
}
if (hotkeyGWI != hotkeyGWI_new) {
Try
If (hotkeyGWI)
Hotkey(hotkeyGWI, "Off")
hotkeyGWI := hotkeyGWI_new
if (hotkeyGWI)
Hotkey(hotkeyGWI, ShowActiveWindowInfo, "On")
}
}

If (hotkey1) {
Hotkey(hotkey1, ToggleKeyMap)
}
If (hotkey2) {
Hotkey("~" . hotkey2 . " UP", ToggleKeyMap2)
}
If (hotkeyGWI) {
Hotkey(hotkeyGWI, ShowActiveWindowInfo)
}

OnExit(ExitKeymap)

A_TrayMenu.Insert("1&", "显示【键谱】", ShowKeymap)
A_TrayMenu.Insert("2&", "隐藏【键谱】", HideKeymap)
A_TrayMenu.Insert("3&")
A_TrayMenu.Insert("4&")
A_TrayMenu.Rename("4&", "热键(组合键): " . hotkey1)
A_TrayMenu.Insert("5&")
A_TrayMenu.Rename("5&", "热键(双击键): " . hotkey2)
A_TrayMenu.Insert("6&")
Pos := 0
A_TrayMenu.Insert(++Pos . "&", "显示【键谱】", ShowKeymap)
A_TrayMenu.Insert(++Pos . "&", "隐藏【键谱】", HideKeymap)
A_TrayMenu.Insert(++Pos . "&")
A_TrayMenu.Insert(++Pos . "&", "热键信息", ShowHotkeys)
A_TrayMenu.Insert(++Pos . "&", "编辑配置文件", EditConfig)
A_TrayMenu.Insert(++Pos . "&", "重新读取配置文件", ReloadConfig)
A_TrayMenu.Insert(++Pos . "&")
A_TrayMenu.Default := "1&"
A_TrayMenu.Disable("4&")
A_TrayMenu.Disable("5&")
A_IconTip := "Keymap Tray"
Binary file modified exe/keymapTray.ini
Binary file not shown.
33 changes: 26 additions & 7 deletions release.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ if not exist release mkdir release
if "%~1" neq "" goto :%~1

call :html
call :clean
call :exe
call :tray

exit /b

Expand All @@ -19,23 +21,40 @@ if exist release\keymap-%__version__%-html.zip del release\keymap-%__version__%-
zip release\keymap-%__version__%-html.zip keymap.html README.md MANUAL.md LICENSE js\* *.example.* keymaps\*
exit /b

:exe
:clean
pushd exe
call build clean
popd
if exist pack_tmp rmdir /s /q pack_tmp
mkdir pack_tmp
mkdir pack_tmp\data
exit /b

:exe
pushd exe
call build exe
popd
if not exist pack_tmp\data mkdir pack_tmp\data
::copy /y keymap.html pack_tmp\
::copy /y README.md pack_tmp\
::copy /y MANUAL.md pack_tmp\
copy /y LICENSE pack_tmp\
copy /y exe\dist\keymap\keymap.exe pack_tmp\
xcopy /s exe\dist\keymap\_runtime\ pack_tmp\_runtime\
xcopy /y /s exe\dist\keymap\_runtime\ pack_tmp\_runtime\
copy /y exe\README.md pack_tmp\README-keymap-exe.md
if exist release\keymap-%__version__%-exe-x64.zip del release\keymap-%__version__%-exe-x64.zip
cd pack_tmp
zip -r ..\release\keymap-%__version__%-exe-x64.zip keymap.* README-keymap-exe.md LICENSE _runtime\ data\
cd ..
exit /b

:tray
pushd exe
call build tray
popd
if not exist pack_tmp mkdir pack_tmp
copy /y exe\dist\keymap\keymapTray.exe pack_tmp\
copy /y exe\dist\keymap\keymapTray.ini pack_tmp\

if exist release\keymap-%__version__%-exe-x64.zip del release\keymap-%__version__%-exe-x64.zip
if exist release\keymap-%__version__%-tray-x64.zip del release\keymap-%__version__%-tray-x64.zip
cd pack_tmp
zip -r ..\release\keymap-%__version__%-exe-x64.zip keymap.* keymapTray.* README-keymap-exe.md LICENSE _runtime\ data\
zip -r ..\release\keymap-%__version__%-tray-x64.zip keymapTray.* LICENSE
cd ..
exit /b

0 comments on commit f22ade7

Please sign in to comment.