Skip to content
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

loads of AHK application icons in task bar wen de- and re-activating hotkeys #216

Closed
nnako opened this issue Jul 9, 2023 · 3 comments
Closed

Comments

@nnako
Copy link

nnako commented Jul 9, 2023

somehow related to #211 , when working with the following functions in a cycle, more and more task bar icons containing the AHK logo appear:

  • add_hotkey( ... )
  • start_hotkeys()
  • stop_hotkeys()
  • clear_hotkeys()

please see the small video which demonstrates the effect:

2023-07-09_registration_cycle_creates_AHK_app_icons_in_taskbar_40_30fps.mp4

the source code is here:

import time
from ahk import AHK

# globals
ahk = AHK()
request_quit = False


#
# callback function definitions
#

def on__ctrl_shift_alt_t():
    global ahk
    global request_quit
    print("CTRL+SHIFT+ALT+T pressed")

    # give some time for the control keys to reset
    time.sleep(0.2)

    # output keypresses
    ahk.send('__TEST__')
    ahk.send('{enter}')
    ahk.send('{F7}')

    # request quit of application
    request_quit = True

def on__f6():
    global ahk
    print("F6 pressed")

    # forward this key to active application
    ahk.active_window.send('{F6}')


#
# configurations and operation
#

while not request_quit:

    # initialize hotkeys
    ahk.add_hotkey("^+!t", on__ctrl_shift_alt_t)
    ahk.add_hotkey("f6", on__f6)
    ahk.start_hotkeys()

    # wait
    time.sleep(0.5)

    # de-initialize hotkeys
    ahk.stop_hotkeys()
    ahk.clear_hotkeys()

    # wait
    time.sleep(0.5)


# reset hotkeys
ahk.stop_hotkeys()
ahk.clear_hotkeys()

# grant some time to flush any pipeline
time.sleep(1)
@spyoungtech
Copy link
Owner

spyoungtech commented Jul 9, 2023

Yeah, this is a known behavior. As you noticed, the icons disappear when you mouse over them and Windows realizes the process is no longer running for those icons and cleans them up. So, there aren't actually that many processes actually running -- it's just the icon that's hanging around.

I'm guessing this happens because the current process for restarting the process is not very nice and goes straight to kill which doesn't give the AHK process the opportunity to gracefully exit and remove the icon on its own (not sure if it will do that anyhow, though). I'm not sure if there's a more graceful way to tell the subprocess to exit here. But I haven't yet had an opportunity to investigate this issue.

It might be possible send some signal other than kill/terminate to stop the process (maybe this requires implementing signal handling in AHK?). It may also be possible to remove the need to actually stop/restart the process to add/remove hotkeys and hotstrings.

As a workaround, maybe hiding the tray icon altogether would work for you. Right now, there is no interface for this with respect to the process used for hotkeys, but is planned as part of #211

@spyoungtech
Copy link
Owner

FYI: a release candidate 1.2.0rc2 is available implementing the feature request in #211

If all works out, it should be included in the upcoming 1.2.0 release, which should be forthcoming.

@spyoungtech
Copy link
Owner

1.2.0 is now released with the ability to hide the tray icon for hotkeys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants