Replies: 1 comment 1 reply
-
Yeah, this is something that is not yet implemented in the API. Technically, you can write this condition into your hotkey callback, but it doesn't quite provide the same behavior as def my_callback():
active_window = ahk.get_active_window()
if active_window and active_window.get_process_name() == 'target.exe':
...
else:
ahk.click(button=3) # send click since it was captured by the hotkey The main difference is that, depending on the hotkey definition, it will block the key still, even when the target.exe window is not active. You can possibly mitigate this by sending the captured key in an I can put it on the roadmap to support this. I just never thought of a great way to implement it, since it technically accepts an arbitrary expression. Though, maybe adding specific support just for use cases like |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to write a hotkey that triggers custom function execution by clicking the middle mouse button, but wants it to only take effect in a specific window. One way is to detect the current window in the custom function and execute the corresponding code only when the target window is active. But I found that it affects the functionality of the middle mouse button in other windows, such as holding down the middle mouse button for multi-column selection in vscode.
An ideal API would be similar to
ahk.add_hotkey('MButton', callback=my_callback, hotif="WinActive("ahk_exe target.exe")")
, which would add#HotIf WinActive("ahk_exe target.exe")
in AHK v2, or#If WinActive("ahk_exe target.exe")
in AHK v1 before the rendered code.I searched the discussion and found #212, but the workaround in it didn't solve my problem. I read the documentation and found that
#IF
is marked as "Not relevant for this library".Is there any plan to implement something like this? Or is there a way to implement context-sensitive hotkeys?
Beta Was this translation helpful? Give feedback.
All reactions