-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(win): IPC communication via Windows messages #1082
base: main
Are you sure you want to change the base?
Changes from all commits
6976120
677fae9
c16cdcd
7d23585
bf98b27
9664003
3cdc1b5
7f0ccbe
3cb4169
0702640
538930e
5ddc311
02fcb3b
da3b6e0
4d4f942
c3b7e3d
4472256
cdfc271
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#Requires AutoHotkey v2.0 | ||
Persistent true | ||
listen_to_Kanata1() | ||
listen_to_Kanata1() { | ||
static msgIDtxt := "kanata_4117d2917ccb4678a7a8c71a5ff898ed" ; must be set to the same value in Kanata | ||
static msgID := DllCall("RegisterWindowMessage", "Str",msgIDtxt), MSGFLT_ALLOW := 1 | ||
if winID_self:=WinExist(A_ScriptHwnd) { ; need to allow some messages through due to AHK running with UIA access https://stackoverflow.com/questions/40122964/cross-process-postmessage-uipi-restrictions-and-uiaccess-true | ||
isRes := DllCall("ChangeWindowMessageFilterEx" ; learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-changewindowmessagefilterex?redirectedfrom=MSDN | ||
, "Ptr",winID_self ;i HWND hwnd handle to the window whose UIPI message filter is to be modified | ||
,"UInt",msgID ;i UINT message message that the message filter allows through or blocks | ||
,"UInt",MSGFLT_ALLOW ;i DWORD action | ||
, "Ptr",0) ;io opt PCHANGEFILTERSTRUCT pChangeFilterStruct | ||
} | ||
OnMessage(msgID, setnv_mode, MaxThreads:=1) | ||
setnv_mode(wParam, lParam, msgID, hwnd) { | ||
if wParam == 1 { | ||
curtime := FormatTime(,"dddd MMMM d, yyyy H:mm:ss") | ||
} else if wParam == 2 { | ||
curtime := FormatTime(,"yy") | ||
} else { | ||
curtime := "✗ wParam=" wParam " lParam=" lParam | ||
} | ||
SetKeyDelay(-1, 0) | ||
SendEvent(curtime) | ||
} | ||
} | ||
|
||
listen_to_Kanata2() | ||
listen_to_Kanata2() { | ||
static msgIDtxt := "kanata_your_custom_message_string_unique_id" ; must be set to the same value in Kanata | ||
static msgID := DllCall("RegisterWindowMessage", "Str",msgIDtxt), MSGFLT_ALLOW := 1 | ||
if winID_self:=WinExist(A_ScriptHwnd) { ; need to allow some messages through due to AHK running with UIA access https://stackoverflow.com/questions/40122964/cross-process-postmessage-uipi-restrictions-and-uiaccess-true | ||
isRes := DllCall("ChangeWindowMessageFilterEx" ; learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-changewindowmessagefilterex?redirectedfrom=MSDN | ||
, "Ptr",winID_self ;i HWND hwnd handle to the window whose UIPI message filter is to be modified | ||
,"UInt",msgID ;i UINT message message that the message filter allows through or blocks | ||
,"UInt",MSGFLT_ALLOW ;i DWORD action | ||
, "Ptr",0) ;io opt PCHANGEFILTERSTRUCT pChangeFilterStruct | ||
} | ||
OnMessage(msgID, setnv_mode, MaxThreads:=1) | ||
setnv_mode(wParam, lParam, msgID, hwnd) { | ||
SendInput("@kanata_your_custom_message_string_unique_id Unknown wParam=" wParam "lParam=" lParam) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#| | ||
|# | ||
(defcfg | ||
process-unmapped-keys yes | ||
log-layer-changes yes | ||
danger-enable-cmd yes | ||
) | ||
(defsrc 1 2 3 4 5 6 7 8 9 0) | ||
(deflayermap (win-msg) 1 1 2 2 | ||
3 (msg❖async 1 ) ;; print date in the ‘dddd MMMM d, yyyy H:mm:ss’ format | ||
4 (win-post-msg 2 ) ;; print date in the ‘yy’ format | ||
5 (win-post-msg 3 ) ;; print error ‘✗ wParam=3 lParam=0’ | ||
6 (msg❖async 3 0 "" "kanata_your_custom_message_string_unique_id") ;; print long message | ||
8 lrld | ||
9 lrld-prev | ||
0 lrld-next | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ thiserror = "1.0.38" | |
# binary. | ||
kanata-keyberon = { path = "../keyberon" } | ||
bytemuck = "1.15.0" | ||
colored = "2.1.0" | ||
num-format = "0.4.4" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not seem worth adding as a dependency. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so you'd be fine with errors like
|
||
|
||
[features] | ||
cmd = [] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#[derive(Default, Debug, Clone, PartialEq, Eq, Hash)] | ||
pub struct WinMsg {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#[derive(Default, Debug, Clone, PartialEq, Eq, Hash)] | ||
pub struct WinMsg {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
termcolor
instead; it is already a dependency andcolored
is not.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but how do you compose it with the rest of the existing macros and log messages and do stuff like
let cmd_name = cmd_name.blue().bold();
which can then be used anywhere. That crate seems to work on whole streams by adding apis to add colors to those