How to disable callback for add_hotkey #212
-
I'm rewriting following ahk script into Python equivalent with this Python ahk library, #IfWinActive ahk_exe WindowsTerminal.exe
^n::
Send, {A}
Return
from ahk import AHK
ahk = AHK()
def my_callback():
win = ahk.active_window
if win.get_process_name() == 'WindowsTerminal.exe':
ahk.send_input("a")
else:
ahk.stop_hotkeys() # Disable callback by stop_hotkeys()
ahk.send_input("^n")
ahk.start_hotkeys() # Resume callback by start_hotkeys()
ahk.add_hotkey('^n', callback=my_callback)
ahk.start_hotkeys() # start the hotkey process thread
from ahk import AHK
ahk = AHK()
def my_callback():
win = ahk.active_window
if win.get_process_name() == 'WindowsTerminal.exe':
ahk.send_input("a")
else:
ahk.add_hotkey('^n') # Disable callback by not supplying callback argument to add_hotkey()
ahk.add_hotkey('^n', callback=my_callback)
ahk.start_hotkeys() # start the hotkey process thread
#include <WinAPI.au3>
Global Const $proc_name = "WindowsTerminal.exe"
While True
If StringInStr(_WinAPI_GetProcessName(WinGetProcess(_WinAPI_GetForegroundWindow())), $proc_name) Then
HotKeySet("^n", "Callback")
Else
HotKeySet("^n")
EndIf
Sleep(100)
WEnd
Func Callback()
Send("a")
EndFunc
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Right now, there is no public interface for this. I am planning to add this functionality in an upcoming release. As a workaround, you might be able to just replace the hotkey by adding the hotkey again with a no-op function under the same hotkey name. That will overwrite the existing hotkey with a new one whose callback simply does nothing, although that's not quite the same behavior as removing it. I'll be updating progress on this in #213 |
Beta Was this translation helpful? Give feedback.
Right now, there is no public interface for this. I am planning to add this functionality in an upcoming release.
As a workaround, you might be able to just replace the hotkey by adding the hotkey again with a no-op function under the same hotkey name. That will overwrite the existing hotkey with a new one whose callback simply does nothing, although that's not quite the same behavior as removing it.
I'll be updating progress on this in #213